One possible reason could be jealousy. Maybe Harry has achieved something great and his friends can't handle his success. For example, if he gets a very important role in a magical competition, his friends might feel overshadowed. Another reason could be a misunderstanding. Harry might be wrongly accused of something, like being in league with the dark side, and his friends, in their fear or haste, abandon him without giving him a chance to explain.
Perhaps it's due to external influence. A powerful and malevolent force could be manipulating his friends' minds. This force might be spreading false rumors about Harry to drive a wedge between them. It could also be that his friends have their own personal issues to deal with. For instance, one of them might have family problems that require their full attention, and in the process, they unknowingly neglect and eventually abandon Harry.
In some cases, it could be a test of loyalty. The wizarding world might be facing a hidden threat, and Harry's friends are made to believe that abandoning him is for the greater good. However, this is a cruel test that leaves Harry feeling betrayed. It's also possible that over time, his friends' values have changed. They might have started to pursue different goals in life that don't align with Harry's, leading to their separation.