Thought broadcasting

Italy here. When i was psychotic, i heard people repeat my thoughts verbatim.its quite distressing. I would think of a specific sentence and id hear a random person (for example, at a restaurant) repeat the sentence. I would be staring at them while this happens and id see their lips move, usually from 2-3 meters away, sometime closer.

Im since on meds and in therapy, and its not as often.

Im curious how does this work in the brain. What is the scientific explanation and the how?

Kind regards, italy