How did the spaceships travel from the Milky Way to the Andromeda galaxy for 6 centuries? How did they not run out of fuel? Or do those spaceship have nigh infinite fuel?
For a start, there is very little friction in space. As a result, constant thrust is not required to maintain velocity, leading to this joke:
Shepard: You wouldn't believe how often I hear [from clueless people] "Why's the ship turning around? We're only halfway there!"
The joke is that, if the ship is constantly firing its thrusters, it will need to begin decelerating at the halfway point in order to be roughly at rest when it arrives. This could be done with reverse-mounted thrusters, but that requires an unreasonable amount of extra weight and engineering compared to using reaction wheels to turn the ship around. Of course, you could instead accelerate up to some cruising velocity and then turn the thrusters off entirely, if you wanted to save on fuel.
Nevertheless, thrusters are required for course corrections, and a constant acceleration profile can shave a substantial amount of time off of the overall trip (which is more important than the use of cryo might suggest, given that the whole ark already has to function reliably and without non-automated maintenance for six centuries). So to properly explain this, we need to go to the codex (Ships and Vehicles > Tempest: ODSY drive):
Standard ship drive cores build up static electricity, and require periodic discharge on a planet or at specialized facilities to prevent static from building to dangerous levels. With few such suitable discharge points in dark space, the ODSY drive core was developed for the arks' long-haul journey to Andromeda. [...]
The ODSY (out-galaxy distributed static synch) drive core is designed to minimize static build-up, and transfers the remaining charge to specially designed capacitors attached to the core. The recycled electricity is used to run ship systems, reducing power requirements and lowering heat generation.
Cross-galaxy, the arks gathered hydrogen using an electromagnetic ramscoop, converting it into protons with an ionizing laser. Proton collision in the arks' fusion reactors provided power for their thrusters. [...]
(The elided portions relate to the Tempest, which is a different ship altogether.)
TL;DR: They found a way to convert the excess static charge which we previously discussed into electrical energy, and then used it to power electromagnetic ramscoops and ultimately fuse hydrogen.