why does phosphorus makes 5 bonds with oxygen in P4O10 whereas 3 bonds in P4O6?
Phosphorus has electronic configuration of [Ne]3S2 3P3 As it is a 3rd period element it also have a vacant 3D orbital.

In case of P4O6 only the 3P3 electrons take part. Resulting in formation of 3 bonds with O. But in case of P4O10 one of the electron of 3S is excited to vacant 3D orbital. Now P has 5 unpaired electron and it can form 5 bonds. Therefore P forms 5 in P4O10.

Now, about the octet. Not every compound follow the octet rule. Just to understand The whole chemistry depends upon STABILITY i.e lesser energy of molecule. Therefore, if by forming more bonds (and does not obeying Octet rule) the molecule is gaining more stability, it will do so.