In LEGO Harry Potter Years 5-7, you start the game with Wingardium Leviosa as your only available spell.
How do I unlock the spells I learned in years 1-4?
Find the Defence Against the Dark Arts class room (follow the ghost chips from the Gryffindor common room). Put the cauldron together and brew the strength potion. Once you drink it you'll be able to open cupboard on the right which triggers an event that will unlock a wider range of spells.
For the first part of the game, the computer will decide what spell you need to advance through the game. However, when you reach the school, your first lesson is defence against the dark arts and it seems like a lot of spells get removed from you. What actually happens is that you are now able to choose form a couple of spells (Wingardium leviosa, Lumos etc). To get back all of your spells you will have to play through the first two years of the story mode. Throughout these years you will play through several lessons, many of which will give you spells, such as, Diffindo, Reducto, and the Expecto Patronum. If you would like the jinxes and charms that you could purchase in the first game, then they are also purchased in this one. You can find them in a shop in Diagon Alley. For the first two years of the story, there is an abandoned shop halfway down the street. It is purple and has boarded up windows. This is where you get your optional spells from. In the last half of the game, this shop becomes Fred and George's joke shop, but you still need to go in here to buy the optional spells.