Some app or service block macbook from locking
Okay, the first thing I'd do is boot your MacBook in Safe mode and test to see what happens.

Boot into Safe Mode

Follow these steps to boot your Mac into Safe Mode:


Fully shut down your Mac
Restart your Mac
Immediately press the Shift key and keep it down 
Let go of the Shift key when you see the login window 
Now log into your Mac and (NOTE: If you have FileVault enabled you may need to log in twice)
Now test to see if your MacBook goes to sleep or not
Exit Safe Mode by restarting your Mac as normal
Once again, test to see if your Mac goes to sleep


If you find that your MacBook still doesn't go to sleep while in Safe Mode or when logged in normally afterwards, then proceed below to resetting your SMC.

If on the other hand you find that your MacBook does go to sleep in Safe Mode, but still doesn't when you're logged in normally, then let me know and we'll troubleshoot further.

Resetting your SMC

Your System Management Controller (SMC) manages a whole range of functions relating to power, charging, your Mac's thermal environment, and so on. Since you're having problems with your Mac going to sleep, this is a good thing to try.

However, since you haven't specified your model of MacBook, refer to How to reset the System Management Controller (SMC) on your Mac on Apple's website. Please read through this page carefully as the instructions differ for different models of Mac.