Manage your Apple Music membership - Apple Support - https://support.apple.com/HT204939 - "Learn how to change from an Individual membership to a Family membership, turn off automatic renewal, or join Apple Music later." Turn off autorenewal and your membership will finish at the end of the current subscription period.
If the above isn't working then you need to provide more details about error messages or what you mean by it isn't allowing you to cancel.