His powers went away when he thought he lost MJ, and he decided to stop trying to be Spider-man because he didn't have his powers. He got his powers back when MJ needed Spider-man.
The premise of the film was to explore the dichotomy that Peter could not have MJ while maintaining a secret identity as Spiderman, but he couldn't be Spiderman if he didn't also have MJ. The situation was temporarily resolved when Spiderman was needed to save MJs life, and fully resolved when Peter revealed his identity as Spiderman to MJ, and she accepted that and embraced it.