Whether a stain on your mattress voids the warranty depends on the specific terms and conditions of the warranty provided by the manufacturer or retailer. Warranty policies can vary significantly, and some may have clauses that exclude coverage for certain types of damage, including stains. (In my thirty years in the business I've never seen a mattress warranty that didn't exclude mattresses that had stains)
To determine whether a stain will void your mattress warranty, you should review the warranty documentation that came with your mattress or check the manufacturer's website for information on their warranty policy. Look for any sections related to exclusions, limitations, or conditions that might affect the warranty coverage. If you're unsure, you might also consider contacting the manufacturer or retailer directly to inquire about the specifics of your situation.
In general, (not in general, always!) it's a good idea to protect your mattress from stains by using a mattress protector. This can help prevent damage and potentially preserve your warranty coverage. If you already have a stain on your mattress, document it with photos and contact the manufacturer or retailer to discuss your options and clarify whether the warranty is affected.