In the formula 5Mg3(PO4)2, the "2" refers to the number of phosphate ions in a single molecule of magnesium phosphate. Therefore, the correct interpretation is:
There are two phosphate ions in a molecule of magnesium phosphate.
This means that each formula unit of magnesium phosphate contains two phosphate (PO4) ions.