Desktop environment disappears after login

Hi. I had an issue this afternoon that scared me a lot. Then I decided to post it here so if someone relates to it may tell me what caused or if it's going to happen again.

I normally turned on my laptop, logged in lightdm and then my desktop environment flashed, then disappeared with my monitor screen turning off. My first action was try to interact with my pad to make it turn on again and show the login screen, nothing happened. Then I tried closing and opening my monitor again so it would show me the login screen and it did, but as soon as I logged in the monitor turned off again.
My next action was press Ctrl+Alt+F5 with no return. I closed and opened the monitor and then I had the Command Line Interface. I tried going back to the GUI with Ctrl+Alt+F7 but then again the monitor turned off. I went back to the CLI updated the packages, upgraded the packages and then rebooted. I thought that would solve the problem, but it didn't.
Desperate I tried closing and opening the monitor again and then that time, for some reason, worked.

I'm concerned that may happen again, so I'm doing a backup of my files and if no one can tell me what happened I'm better off upgrading to the 20.04 and hope that doesn't happen again.

My specs:
Laptop: Dell Latitude E7240; Kernel: 5.4.0-86-generic
CPU: Intel i5-4310U; GPU: Intel HD Graphics 4400
Shell: bash 4.4.20

Everything else is just standard from the installation.

Sounds like a slightly malfunctioning lid-switch:
(monitor open but switch doesn't detect it and puts the laptop in 'sleep' as soon as you login)

try this setting:
controlcenter->powermanagement->when laptop lid is closed: Do Nothing
(both for 'on ac' and 'on battery)

If the problem does not appear anymore, it is a faulty lid-switch.
(a hardware problem that can be solved by repairing/replacing the switch)