From the distance/information provided some guesses.
As you state it works most of the time and then the custom collection loading fails: Could be that the threaded loading may have an impact.
To switch the threaded loading: Locate your es_settings.cfg (usually /opt/retropie/configs/all/emulationstation. Spot the entry <bool name="ThreadedLoading" value="<your_value>" /> and bool invert that <your_value> (e.g., true gets false and vice versa).
Then run this config for a while / for several reboots and note if your reported effect still occours.
To avoid the daunting task of re-enabling all of your collections in ES make a copy of <string name="CollectionSystemsCustom" value="yadayada,yabadaba,..."> and keep it in a safe and dry place thus you can restore it if you encounter the effect again. But only do edit your es_settings.cfg while ES is not running. And do not put an extra space between the delimiter (,) if you want to edit collectionnames manually in the editor.
Also make sure you only use ASCII characters for your collection custom-*.cfg files. (But I doubt this is the cause, as the custom collections loading would fail everytime).
Last but not least: The pugixml, which is an external lib to ES and is actually handling every xml in ES (f.i., es_settings.cfg) is a little dated (1.8 from 2016), current is 1.11.
Maybe updating remediates your issue. However, I skimmed over their releasenotes/issue tracker but did not find on a cursory look a bug directly linked to long string reading (i.e., your value of name="CollectionSystemsCustom").
HTH