Great question! For what you've described, I would personally choose 'involuntarily'. This means 'without will' or that you didn't choose - or volunteer - to have those thoughts.
But 'automatically' also works too in this context (which almost means the same as 'involuntarily', but instead of YOU not choosing the thoughts, it means 'the thoughts happened by themselves TO you, with no direct human control').
'Unconsciously' means more like 'you weren't aware of the thoughts'.
Hope this helps! You asked a great question here, as these words as so similar and have such nuanced meanings.