Its something of a myth but not completely.
For women, if the hymen is still intact it can tear during the first time having penetrative sex and that can be painful plus accompanied by blood. However it is a myth that the hymen is intact in all virgins and that the first time is painful for all women.
For men, the first time penetrating someone can rarely be painful too if they have not retracted their foreskin much before or it is tight. Some men don't realise they can retract their foreskin fully when masturbating for example, and may not be told by anyone (particularly is homes that may by uptight or even puritanical about sex education). So it does genuinely happen that people find out when they first have sex. For most men the foreskin will stretch a bit over time and tightness or pain will resolve but occasionally they need a circumcision.
Men with circumcisions may also experience pain the first time if theyve has a bad circumcision and the scar is restricting them or being pulled on during penetration. Again that usually settles but very rarely may need surgery.
Meanwhile for anal penetration, the first time is often painful largely due to inexperience. People are not used to relaxing the anus, or are nervous and tighten it. Also if they have a bad partner they may be too aggressive which can be very painful, or they may not use enough lube.
So yes the first time can be painful, but is a myth that it must be painful or is always painful. Pain can be avoided . Persistent pain every time sex is had may be due to poor technique but may also warrant a medical check up - for either gender/sex.