So I pulled the thermostat to see if that was bad and it was still good also checked my oil and it wasn’t milky but I pulled the radiator cap off and this was built up on it And I’m wondering what may cause this
So I'm guessing at one time your vehicle had a slight coolant leak. The owner added some coolant stop leak to the system. There are lots of forms of this... here's a typical summary. I know lots of folks have recipes for leak stop stuff.. the one I remember from old skool mechanics is to use raw ground pepper as a leak stop filler.
Generally stop leak adds small granular material to the coolant system. The theory is that these small particles migrate to the leak locations and plug the holes. And I'm not saying that's a bad thing. At the manufacturer I worked at we added this material to the coolant system of each and every new vehicle built. The material we used came in a compressed pellet, which when added to the radiator after coolant evacuation and fill would migrate throughout the system. The pellets were basically just ground up almond shells. No kidding. Almond shells. It seemed to work, and I remember a particular new model launch issue where we proved that the stuff was necessary. We never saw any system (quality) degradation anywhere from its use.
The stuff you have seems like more of the same, likely of a different form. There are liquid versions of the stuff, and I'm guessing that's what you have. Probably lots of it. I wouldn't worry about the sludge. Note: once in there, you can not get it out again. Trust me, I've tried (when I had that issue at a new model launch. One the stuff is in there it stays in there...)
But... with that said, that stuff was added for a reason. Please do test your coolant system, check for leaks. Verify the radiator cap is in good shape, and that your overflow (and coolant return) system works well. Keep an eye on that. You don't want to run dry, overheat your engine, etc...
Good luck with it.