When checking wether pathPrefix sould be removed or not, it is assumed that you already are in a subfolder of the PathPrefix. The case where you want to go to the root of your pathPrefix folder is not properly handled.
Let's say "MyPathprefixFolder" is the home folder for a siteaccess, then you'll have in your site.ini
When switching language directly from your homepage, the PathPrefix is added to the new language:
mywebsite.com/switchlanguage/to/fr/ redirects to fr.mywebsite.com/MyPathPrefixFolder instead of just fr.mywebsite.com.