Moving Through Other Starships
Since the hexes in starship combat aren’t representative of three-dimensional distance, starships can move through hexes containing other starships, but they can’t end their movement there. If a starship moves through a hex containing an enemy starship, the enemy starship can fire any one of its direct-fire weapons from any arc at the moving starship, targeting its aft quadrant. This free attack doesn’t benefit from any bonuses or additional abilities from other actions taken aboard the enemy starship, such as divert or lock on. Any character currently in a gunner role can make this attack. If no one is designated as a gunner (often the case in starships with only one crew member), the enemy starship can’t make a free attack. A weapon used for this free attack can still be used as normal later in the round.
Source
Core Rulebook pg. 319