Because Kakashi didn’t want to kill Rin, during the Third Shinobi World War, Rin ended up impaling herself on Kakashi’s Chidori (his concentrated lightning chakra) while hiding in the mist so that Kakashi wouldn’t notice until it was too late. She died right then and there, in front of Kakashi, who fainted soon after and developed PTSD in the aftermath. According to the fandom, Kakashi struggled for years with her death, which haunted him even as an adult.
Obito, Rin’s best friend, watched the events go down from a cave where he was trapped, unable to intervene. Once he was free, Obito fought and won against the enemy ninjas he, Rin, and Obito were meant to defeat. Though Rin wasn’t aware of it, Obito had fallen in love with her, which made her death that much more difficult for him to deal with. Obito later vowed to make a world where he and Rin could be together again, and according to the fandom page, Rin watched over her best friend after her death.
Even though Rin killed herself, three-tailed beasts can never truly die; they just change forms. So after the beast was destroyed, it transformed into free-flowing chakra with no clear direction. Rin’s spirit lives on in the afterlife, but it’s not exactly clear what happened to her body. It can be assumed that Obito made sure she was buried and took her back to her village’s cemetery.
View more information: https://www.distractify.com/p/why-did-kakashi-kill-rin