Most of the time, yes, anyone can stay in a hostel. However, sometimes there are pretty specific guidelines for who can stay in a certain hostel. It all comes down to the specific backpacker hostel property.
While some hostels do restrict themselves to certain tenant genders the vast majority are open to anyone, regardless of what age, nationality, or gender you identify as. It doesn’t matter to most hostels because they want to provide backpackers with cheap accommodation.
The terms of staying in a hostel should be clearly stated in the description or when you go to book a room at the hostel.