Yes, I completely replaced all Silverstripe folders. I have no other modules installed, only custom code for extending Page and Form. I don't think I can remove my page types, run dev/build and keep the content intact? But I think I found out why the HTML structure is continuously growing, at least I think it is closer to the actual problem. I will explain.
I noticed in Firebug that the javascript sapphire/javascript/HtmlEditorField.js is loaded, which contains an ajax call to getimages() in admin/EditorToolbar/ImageForm. The Response headers for this call contains a header called "X-Include-JS" which has 41 comma separated URL:s to javascript files as its value. These files are then loaded and the last of these files is sapphire/javascript/HtmlEditorField.js, which makes another ajax call to admin/EditorToolbar/ImageForm::getimages() and round it goes. The ajax call is conditioned, so in this case apparently the following condition is always true:
if($("#FolderImages").length > 0 && $("body.CMSMain").length > 0) loadImages(false);
To clarify, the 2.3.7 installation has the "perpetual hang" issue which is that you log in and click on a page and the progress cycle icon never stops (I don't know when the problem started, it was not always like this). The 2.4.5 installation upgraded from said 2.3.7 installation behaves like I describe above with an infinite loop of loading javascripts.
I will make a new copy of the 2.3.7 installation and upgrade it to see if the same problem occurs again. If it does, I'll remove any custom code and start from there as you suggested Ryan. Thanks for the tip.