There are a couple that come to mind, one when I was a teenager and one when I was younger.
The one where I was younger was in the hospital. It was one of many “random exams” I got during my hospital stays. This was the 1970s or early 1980s in a teaching hospital. And back then, it was routine for interns / residents / med students to be told to go do exam X on patient Y. Or to do exam A on all of the patients under your care. Mostly to learn. And if you were a kid, you weren’t usually asked. (Although, sometime you or your parent would be aske. It seemed to be random.) These exams sometimes had only the most tenuous connection to why you were there, but they wouldn't be painful or dangerous. Most weren’t even partially embarrassing. They were common things that were done.
I don’t remember exactly how old I was, but it was before I was old enough to be moved to the “older teens section” of the peds floor. I was in for an orthopedic surgery. I remember one day, one of the residents/med students coming into my room out of the blue and telling me that he had to do an exam. I don’t think that he pulled the curtains or explained much about why he was doing the exam. He had me roll over on my tummy, like for a temperature taking, and opened up my gown. I felt a finger go up my bottom and come out and then he left. The whole encounter could not have taken more than a couple of minutes. It was like he had a long list of patients to do rectal exams on before he could go home for the day. LOL.
The next one that was a surprise shouldn’t have been a surprise, but I was probably 14 or 15, so I was surprised. My mother had taken me to the ER because I had some blood in my urine and it was after normal hours. I had given a urine sample and we were back in a curtained cubical when a female resident came back to examine me. She did the normal things including thumping my back and doing an abdominal exam. I had to take off my underwear so she could examine my penis including looking in the meatus.
Then she surprised me by saying that she had to do a rectal exam and that I needed to roll over. I was not expecting this. It was bad enough getting a genital exam in front of my mother. I figured that it would be like getting my temperature taken rectally when I was little, so went to roll over on to my stomach. She them told me no, she wanted me on my side with legs pulled up. I did as she asked and soon felt her finger penetrate my anus and go all the way in. It seemed like she felt around there forever, but it was probably less than half a minute. That was pretty much the end of the exam. I got an antibiotic prescription and was sent home with follow up instructions.
Anyway, those are the only two real surprise rectal exams that I remember. Every other one has been pretty much expect.