Hostels are generally safe, and millions of solo travelers, including plenty of solo women, use them happily; the safety question is really about choosing well rather than avoiding them. The risks that actually materialize are mundane: petty theft of unattended valuables, occasionally an uncomfortable dorm-mate, and poorly managed properties with lax access control. Violent incidents are rare in reputable hostels.
Screening is your main tool. Book places with lots of recent reviews and strong scores specifically for security and staff, and read what women reviewers say if that's relevant to you; female-only dorms are widely available and a sensible choice for first-timers.
On-the-ground habits: use the locker for passport, electronics, and cards every time you leave the room and while you sleep, keep valuables off the bed, note the location's neighborhood and how you'd get back after dark, and trust your instincts about people; moving rooms or hostels is always allowed.