She had to practice piano for two hours.

Literal

She [topic-は] piano [object-を] two-hours practice if-not-do not-become-was.

~なければならない ('must, have to') is a cumbersome but important construction, built literally as 'if-not-do, it-won't-become' — a double negation that yields obligation. The past form なければならなかった shifts that obligation into the past: 'had to.' Casual variants include ~なきゃならない and ~なくちゃ, used in everyday conversation. Note the duration 二時間 ('two hours') sits unmarked next to the verb — Japanese typically doesn't take a particle on duration phrases, distinguishing them from at-time expressions which take に.