2.4 and 2.7 are quite old ... neither supported for fixes now - if it is a bug. Don't re-call anyone ever reporting such a problem.
No longer have a 2.4 nor a 2.7 now to see if I could mess them up enough to exhibit behavior you are seeing.
To the best of my knowledge about DB's and MySQL ... there is no cache Moodle (any version) would get confused about.
Have you checked on the health of the DB's? Any tables in need of repair?
Could you save a backup (no user) of one of these errant courses and provide it to someone else for 'inspection'?
One last thought ... in the past folks desiring to reduce code, etc. they used 'special' apache stuff in config.php ... using apache variables for site/location rather than the 'standard/stock' way.
'spirit of sharing', Ken