Royalties are not coded on chain. In cases like Opensea when you mint, the platform will ask you what royalty percentage you wish to receive at every sale, but it is not creating a self-executing smartcontract to extract and deliver royalties at every sale. A royalty on an NFT is just as close to a kind request to support the original artist or creator of the asset, it's not a law, it's not enforceable. In fact Opensea as a centralized third party organization collects at sale both it's 2.5% share and your royalty, to later deliver it personally to your wallet; sadly is not a trustelss and permissionless system, it's absolutely centralized.
Royalties were introduced as a concept in NFTs by Power DaDa in a collaboration with Larva Labs (creators of Crypto Punks). The goal was to create a system to allow, during digital trading of art, a continuous and perpetual sustaince of the original artists and his right as creator of the artwork.
Unfortunately no one stops speculators and value extractors from completely disregarding this written, yet not mandatory request. You coud transfer an NFT to someone and receive cash or get transfered some crypto through an exchange, avoiding royalties completely. The situation becomes more dramamtic, when a marketplace is created to cater specifically to value extractors: SudoSwap. Most ETH NFTs are purchasable from SudoSwap with only a 0.5% service fee and no royalties; you kindly asked and they said NO. They broke the social construct, they unveiled the lie of royalty self execution.
SudoSwap presents itsef as a great polarizer, dividing speculators from collectors. A collector purchases an NFT with the desire to support an artist, a speculator purchases with the goal to flip at the maximum gain.
Not all evils come to harm, as this embodiement of greed will provide us with countless opportunities to discuss and analyze better solutions to support artists, while at the same time it will unveal who is here to build and who is here to ransack the Web3 world. It's an elegant realization that this ecosystem in order to thrive needs noble people to operate on socially accepted basis of merit and responsibility.