Body swapping has become a popular theme in Japanese media because it has been part of Japanese tradition and culture. Various Japanese beliefs has mentions of body swapping and this has become an inspiration for various literary forms in Japan which continued for centuries. This was evident when Makoto Shinkai was interviewed and asked for the inspiration for Your Name(See Ref.1).
Director Makoto Shinkai says that Your Name to have been inspired by a classic Japanese 12th Century tale, Torikaebaya Monogatari, which features a sibling duo, where a boy is raised as a girl and the girl raised as a boy because of their personality.
In Your Name the characters wake up from their dreams as each other and the line between reality and dreams constantly blurs. This aspect of the film, Shinkai says, was influenced by a famous Japanese poem titled Yume to Shiriseba. It reads:
I wonder if he appeared in my dream because I fell asleep thinking of him.
I wouldn't have woken up if I had known it was a dream.
That melancholy moment of bleary wakefulness after a dream is the sensation Shinkai appears to have been reaching for in this film.
Not only ancients tales but he also took inspirations from other body-swap manga like Inside Mari, Ranma 1/2 and non-Japanese media like Safe Desposit Box and Christopher Nolan’s Interstellar.
Your name also contains several Japanese beliefs. One of them was musubi, the belief that two people are forever connected, regardless of place and time. This is a big part of Shinto religion (see "red thread of fate" in @CeesTimmerman's answer).
Another aspect of this is that body-swapping stories touches upon themes like adolescent dreaming, aspirations and the struggle to assert your identity in a confusing world which most Japanese teens and adults seeks out and has an "obsession". This is called Chūnibyō (中二病) and is a word to describe early teens who have grandiose delusions, who desperately want to stand out.
The market for making body swapping anime and manga never dies down because Japanese audience especially teens relate to the stories and themes. These stories are portrayed in such a way that it touches upon specific aspects prevalent among Japanese teens. The examples in my question has those aspects: Japanese adults growing in villages trying to settle in urban towns(Your Name), insecurities in the form of "Adolescence Syndrome" (Rascal doesn't dream of Bunny girl Senpai), how deep is your friendship (Kokoro connect) etc.
Notes and references
- Why the story of body-swapping teenagers has gripped Japan?
- JAPANESE TEENS ARE OBSESSED WITH THIS DREAMY BODY-SWAPPING ANIME
- The World Of ‘Your Name’
- Is chuunibyou syndrome real?
- The first instance of body swapping in a Japanese TV film was I Are You, You Am Me(1982)