James and Lily are both in Gryffindor. Lily Evans had been a Gryffindor Prefect.
The appointment of Prefects and Quidditch captains happens with the Hogwarts letter which arrives in August, so presumably the announcement of Head Boy and Girl would also be made in those letters. Since James and Lily started Hogwarts in 1971, they would be starting their seventh year in 1977.
James, however, was not a Prefect. Remus Lupin was the Prefect for Gryffindor during those years. How James became Head Boy is a bit of a mystery. Part of this mystery may have been explained by Hermione's statement in HBP6 that being Quidditch Captain "gives [Harry] equal status with prefects". Perhaps the Head Boy and Girl are chosen from the Prefects and the Captains of Quidditch.