Illegal moves

This is just bizarre. A move is illegal if it is not legal. What other explanation would you have in mind?
If I understand your question correctly, this usually occurs when you try to move a piece that would cause your king to be in check by your opponents piece. Also occurs if you try to move a king into check or when castling you move your king through a check.

I don't understand why a move is illegal in a game. How do I get an explanation
Get a copy of the rules used by the governing body/website that you play under and read them.
Yes it happens when I try to move a king that is in check. I am a beginner, I try and move out of check with no luck. I do not see where the move would keep me in check

Yes it happens when I try to move a king that is in check. I am a beginner, I try and move out of check with no luck. I do not see where the move would keep me in check
Can you show the example?
What probably happens is that your move doesn't bring the king out of check, or it brings it into another check. But for someone to confirm it, we will need to see the position.
The way a piece moves is a legal move. If it moves another way it is an illegal move. A king castles is a legal move. A king castling while in check, or passes through check, or ends up in check would be an illegal move. As others have said learn the rules, and if you follow the rules it is legal. If you do not follow the rules it is illegal.
when I try to move a king that is in check. I am a beginner, I try and move out of check with no luck. I do not see where the move would keep me in check.
Then you must look harder until you see why, but understanding all of the rules will help.

Weirdest illegal move of all time here:
This is the position:
I play cxd5. My opponent plays however you notate it.
Not only did my opponent dodge a capture but they moved my d-pawn to the c-file 💀

Weirdest illegal move of all time here:
This is the position:
I play cxd5. My opponent plays however you notate it.
Not only did my opponent dodge a capture but they moved my d-pawn to the c-file 💀
🗿 fly hax

Weirdest illegal move of all time here:
This is the position:
I play cxd5. My opponent plays however you notate it.
Not only did my opponent dodge a capture but they moved my d-pawn to the c-file 💀
It's safe to say that it did not happen. Maybe you are confusing two different games.
I don't understand why a move is illegal in a game. How do I get an explanation