A community can have many owners, and must always at least one owner. Thus, if you're the only community owner you will not be able to leave the community. Below steps explains how you can transfer ownership to another person.
Only community owners can transfer ownership of a community.
If the person is not already a member, then invite the person you want to transfer ownership to. Already when you invite the person you can choose the owner role for the person.
If the person is already a member, then the change member role to owner.