Philip was one of the deacons. They were probably not yet authorized to perform the mystery of the laying on of hands, which was later replaced by chrismation. At that time only the apostles could perform it. Therefore their presence in Samaria was required, to seal the believers with the gifts of the Holy Spirit, which they had initially received in baptism.
"Why did they not receive the Holy Spirit after baptism? Either because Philip did not impart Him, perhaps giving this honor to the apostles, or because he himself did not possess this gift," that is, to impart the Spirit to others, "since he was one of the seven deacons. The latter may be said with greater probability. When he baptized, he did not impart the Spirit to those being baptized, for he did not have such authority. This gift belonged then only to the twelve. How, someone will say, did they, the Samaritans, not receive the Spirit at all in baptism? They received the Spirit of forgiveness of sins, but had not yet received the Spirit of signs" (Chrysostom, cf. Theophylact).
When they came, the apostles prayed, laid hands on them, and they received the Holy Spirit. It appears that the prayer was common, for all who had believed and been baptized, that they might receive the Holy Spirit. This was done before the laying on of hands. Then the actual laying on of hands followed upon each baptized person separately. As hands were laid upon each one separately, each received the Holy Spirit.