Why are sweat stains yellow?
The yellow you’re seeing is a mineral deposit. Sweat contains salts and other minerals. I’m not sure what part of sweat is yellow (maybe Potassium?), but that yellow stain is common on white shirts. It’s perspiration residue. If your baseball caps are machine washable, you can remove the yellowing with White Vinegar. Pour the vinegar on the marks. Let that sit for about 20 minutes. Then launder as usual. I would NOT machine dry the caps, tho. Machine-drying them could tear them apart. I would allow them to air dry. If the caps are not machine-washable, I would take them to a dry cleaner. The dry cleaner can probably get rid of the yellowing for you. Good luck.