Locking onto ships in Starfield is a bit different than locking on enemies on foot. It requires specific maneuvers and more importantly a perk that you need to unlock.
Your spacecraft is much more than a glorified transportation vessel, as it can also allow you to engage in combat when traversing space. While you may not engage in space combat as regular combat, you will do it eventually. Oftentimes times it can be much more difficult, which is where locking onto ships comes in.
Locking onto ships in Starfield allows you to target your enemies better. Your shots will land right where the enemy is weakest. And you will not have to manually aim.
Starfield Locking on Ships in Combat Explained
In order to lock onto the ships, you need to attack them, and then the game will lock onto them.
Locking on Ships during combat in Starfield requires an unlocked specific perk. This is the Targeting Control Systems perk which is found in the Tech perk tree.
This perk allows you to not only lock onto ships but also allows you to target specific parts of ships. You can target ship engines in Starfield using this method.
This is a tier 1 perk so you should be able to acquire it fairly early on in the game. Once you have the perk unlocked, the next time you aim at a ship in space, you will be able to lock onto it. The perk can be upgraded four times to make it more effective.
Rank 4 reduces the time it takes to lock onto a ship by a staggering 40%. Since perks are passive, they will automatically apply to your character. To lock on, you still need to do a couple of things.
Firstly, make sure you are in a range of at least 500 meters from the enemy ship. When in range press the targeting button.
On Xbox, it is the A button, and on PC it is the E key. This will lock onto the ship in Starfield allowing you to make precise shots on the enemy.