MacBook sleeps on changing lid inclination
Usually it comes down to one of a few things. Here are a few based on the info there is to go on.

Reset the System Management Controller 

To resolve nearly every power related issue on a Mac you can reset the SMC (or System Management Controller0. This will dump and reset settings for anything power management related, and is long known to resolve problems with things like fans, heat, sleep problems, display issues, etc.

On any modern MacBook Pro or MacBook Air with a built-in battery, which is just about all of them nowadays, this is how you do that:


Shut down the Mac and connect it to your MagSafe adapter and a wall
outlet as usual
Hold down the Shift+Control+Option+Power button at the same time for 5 seconds.
Release all keys at the same time
Boot the Mac as usual


Try a PRAM/NVRAM Reset

If the above trick failed, a PRAM reset can at times do the trick, and this is done upon restarting the Mac similar to an SMC reset:


Reboot the Mac and as soon as you hear the boot chime, hold and keep down the Command+Option+P+R keys together
When you hear the boot sound again, the PRAM has been reset so you can now let go of the keys and let the Mac boot up again as usual


Lastly, it can be hardware that is beginning to fail or failing.

A good way to check is by running Apple Diagnostics located on your computer.
There is a process in which it should be run and you can read the full documentation at Apple's website.