Throughout this excellent poem, Melancholy is referred to as "she," indicating the female form that Keats chooses to give her. However, the comparison you are referring to comes at the end of the poem, where, in the final, third stanza, Melancholy is described using a metaphor that compared her to some form of Queen:
Ay, in the very temple of Delight
Veil'd Melancholy has her sovran shrine,
Though seen of none save him whose strenuous tongue
Can burst Joy's grape against his palate fine;
His soul shall taste the sadness of her might,
And be among her cloudy trophies hung.
Note the point that Keats seems to be making about Melancholy here. Melancholy dwells actually in the same place as Delight, but can only be experienced by those who have "burst Joy's grape" in their mouths. Melancholy is here directly personified as some form of Queen who collects "cloudy trophies" of those who have succumbed to her might. Melancholy and Joy are seen to operate together, with Melancholy representing the flip-side of Joy once we have moved away from that emotion.