If you wish to transit the UK to another destination, the visa rules will change depending on your final destination.
If you are transiting the UK and your final destination is the Republic of Ireland or another place, you will not need a visa. However, you will need to bring evidence of your journey to show to UK border officials.
However, if you are transiting through the UK on your way to the Channel Islands or the Isle of Man, the need for a visa will depend on the reason for your journey. In this case, the rules described in this guidance for ordinary entry to the UK apply.
The Honorary Consulate of San Marino endeavours to keep the information above updated but strongly recommends checking the UK government website for any eventual changes.