What is the moral of this story or the lesson to be learned?
The major moral of this story is that a person must keep an open mind. Things are not necessarily as they seem and people who do not keep an open mind expose themselves to danger.
This can be seen most clearly in the interactions between Harry and his friends and the various animals (real animals or the the animal versions of animagi) in the story. The friends consistently misinterpret the intentions of the animals in the story. For example, Harry and Ron spend much of the story being angry at Crookshanks for trying to kill Scabbers all the time. As another example, Harry is terrified by the big dog. Relatedly, everyone is afraid of Sirius Black. All of these perceptions turn out to be wrong.
Because of their inaccurate perceptions, the friends get themselves in trouble at the end of the book. They also inadvertently help Voldemort by letting Scabbers/Pettigrew return to him.
The book is all about thinking you know something when you really are wrong. It is about how we endanger ourselves when we are so sure of something that we do not allow ourselves to consider that we might be wrong.
In this book, Harry learns about the power he has within himself when he casts the Patronus spell to save himself and his godfather, Sirius Black, from the dementors. He originally thought that the Patronus must have been cast by his father, who he thought that he'd seen, but it was really Harry (who, with Hermione, used the time-turner to go back in time). Initially, Harry waits and waits and waits for his father to come and save him and Sirius, but when it becomes clear that no one is coming to save them, he learns to rely on himself. It's a pretty empowering moment for Harry, and it certainly increases his self-confidence, suggesting that we are all more capable than we believe. Harry is a young wizard, yet he handles such an advanced spell. I think this is meant to help empower young readers to feel confident in themselves and their own capabilities.