compulsory
Required by rules or law; not optional.
Compulsory means required or mandatory. When something is compulsory, you don't get to choose whether to do it: you must do it because a rule, law, or authority says so.
School attendance is compulsory in most countries, meaning children must go to school up to a certain age. It's not optional, even if you'd rather stay home. When your teacher assigns compulsory reading, everyone in the class has to read those books. Some schools have compulsory uniforms that all students must wear.
Compulsory things aren't necessarily bad: they're just non-negotiable. Wearing a seatbelt is compulsory in cars because it keeps people safe.
The opposite of compulsory is optional or voluntary. If gym class is compulsory, everyone takes it. If choir is voluntary, only students who want to join need to participate.