Log Shipping utilises an executable called SqlLogShip.exe. As per the documentation, when it runs as part of the LSBackup job, it removes old backup files outside the defined retention period on the primary:
The backup operation creates the log backup in the backup directory.
The sqllogship application then cleans out any old backup files, based
on the file retention period. Next, the application logs history for
the backup operation on the primary server and the monitor server.
Finally, the application runs sp_cleanup_log_shipping_history, which
cleans out old history information, based on the retention period.
When it runs as part of the LSRestore job, it removes old backup files outside the defined retention period on the secondary server:
Any backup files in the destination directory that were created after
the most recent restore point are restored to the secondary database,
or databases. The sqllogship application then cleans out any old
backup files, based on the file retention period. Next, the
application logs history for the restore operation on the secondary
server and the monitor server. Finally, the application runs
sp_cleanup_log_shipping_history, which cleans out old history
information, based on the retention period.
Provided your retention periods are set and SqlLogShip.exe is executing correctly, it should maintain the log files on both the primary and secondary locations.