Body anatomy
Do erections happen for no reason?
Yes, and that is completely normal. Erections happen with arousal, but also during sleep, on waking, when you are anxious, when it is cold, and at times you cannot predict. They are not a sign that you are thinking about anything particular.
What this does and does not tell you
This is general information, not a diagnosis. Only a clinician can examine you, take your history and run tests. The same symptom has different causes in different people.
If something is sudden, severe, or getting worse quickly, get medical advice rather than reading on.