You totally can. I have seen people living in them for months. To learn a language, or in party hostels to enjoy the summer. When I was young spending a few weeks in a hostel was my favorite way to spend time between house hunting in a new city.
You totally cannot in many hostels, maybe it's a thing in the US but I've been to many hostels in the world and some will limit your stay to a few days.
Just like AirBNB hosts.
At least there you have much more choices. I personally never ran into this doing airbnb.