Macbook dying for no reason

So I've been having this problem with my 2017 Macbook Pro recently. If I leave it sitting with it closed and not charging for more than an hour or so, whenever I go to use it, it dies. It doesn't matter how charged it is, it "dies". I have to put the charger in it in order for me to be able to open it up and actually use it. Once I've opened it and put in my password, I can remove the charger and use the computer no problem. Also, if I were to leave it sitting open when I'm not using it, whenever I go to use it again and wake the screen, it works just fine.

I have no other battery issues other than this. It charges how it should and while I'm using it, it holds a charge for as long as it should.

Does anyone know why it's doing this? Or if I can fix it?