Yes such is an
ancient problem (one finds in ancient writings say from the 15th century etc). Some with scruples can particularly tend towards this problem (again this has long been observed in those with such).
Also (we cannot give medical advice etc here) those with OCD suffer this sort of thing. But even those without scruples or OCD can experience such at times.
What to do?
Discuss the following with your confessor.
(for OCD one would seek treatment and counsel etc from a doctor etc --Jimmy Akin on such:
jimmyakin.com/2005/04/a_crown_of_thor.html).
Ignore them.
Be calm.
Do not consent of course.
But do not try to knock them all on the head.
Do not try so much to directly oppose them (such will have the side effect often of increasing them).
Turn to God (or even some good thing) and let them pass by.
Look at the crucifix and continue your prayer etc (let them pass by).
For a thought that occurs to you to be a sin --one must
consent to it. Endorse it with your will.
(and note too that all sorts of thoughts can “happen” to a person contrary to their wanting them and there be not even the slightest sin – nothing possible to confess or even).