IIRC, the first eye transplantation ever shown in Naruto is when Kakashi got his Sharingan from dying Obito. At that time Rin was there to perform the transplantation and she was a medical ninja. Considering Obito's condition (he was crushed by a rock) I'd say that it doesn't hurt for him to have his eyes taken, because the damage he received would have made him numb to further pain. Was it hurts for Kakashi? Maybe. One thing for sure is that Rin was there to perform the surgery and being a medical ninja, she would've ensured that the transplantation is done as hygiene as possible. Kakashi was then shown to be able to use his newly transplanted eye possibly because Rin used medical ninjutsu to heal the area around his eyes, while also reconnecting the nerves to the eyeball using chakra. As mentioned during Sakura's training under Tsunade, medical ninjutsu works by using chakra to control the regrow of cells, thus healing the wounds.
The next one shown to have the eye transplantation was Uchiha Sasuke, but that was done in a hideout with Karin (a medical ninja) there. Karin is an experienced medical ninja, having worked under Orochimaru for years, thus doing something like Rin, and in a better environment should be easy for her.
And then we have Uzumaki Nagato. He got his Rinnegan from Uchiha Madara. Since Madara himself was the one who did the transplantation, and since Nagato is an Uzumaki, who is known to have a huge life-force, there should be no problem whatsoever with the transplantation.
Lastly, we also have the case where Black Zetsu took Rinnegan from Obito. Does it hurts? Yes, as seen from the pain Obito was in when Black Zetsu took the eye. Uchiha Madara then installed the eye, but with no help from other people and he just put the eyeball and puff, it's working like normal. The reason it is possible is that at that time Madara already have the Senju DNA, which enables him to have an accelerated healing, something that Tsunade noted to have been a trait of his late grandfather, Senju Hashirama, which is also the inspiration for her to develop medical ninjutsu in the first place.
So yeah, there is an in-universe explanation on how the eye transplantation works. Note that there is an inconsistency between Kakashi and Sasuke's case. Kakashi was able to use the eyes immediately but Sasuke wasn't able to despite being in a better condition.