Laptop goes to sleep right after boot with lid closed and external monitor connected

Solution 1:

The problem appears to be you have one setting for when user is logged in and another setting when you're at the greeter (lightdm).

I solved this problem by editing /etc/UPower/UPower.conf and changing IgnoreLid=false to IgnoreLid=true at the end of the file.

After restarting, closing the lid didn't put the computer to sleep anymore.

I used this question as reference: Stop laptop from suspending when closing lid in lightdm

Note: someone asked there if this wouldn't disable the lid behavior for every users. I really don't know.