How do I troubleshoot an occasional login failure/black screen?

Sometimes after booting up when I punch in my password and press enter, the screen just stays there for a while, then after it goes black, only the mouse cursor is visible.
Most of the time I can log in without issues.

The setup is an Ubuntu 22.04.2 LTS, with KDE installed.