1- Allah created us to try us. This is part of that divine system of trying this Ummah. Allah wants Muslims to use their intellect and search for the truth. Just because the Prophet (s) accompanied someone does not mean they are good.
2- The Qur’an tells us there were many hypocrites in and around Medina. Why did the Prophet (s) accompany them? He lived with them and he didn’t fight them. He let them come to his mosque.
3- It’s also a trial for the Prophet (s). Being with hypocrites yet being patient and maintaining your Akhlaq is not easy. Allah elevated the Prophet (s) through such a trial.