A port rule can’t help with IPsec traffic, because ESP and AH are protocols of their own and have no ports. ufw does have a way to write these rules, but the man page says it only works in one syntax.
sudo ufw allow to 10.0.0.1 proto esp
sudo ufw allow to 10.0.0.1 proto ah
According to the man page, IPsec is supported through the esp (protocol 50) and ah (protocol 51) protocols. You can restrict a rule to a source network as well:
sudo ufw allow to 10.0.0.1 from 10.4.0.0/16 proto esp
That lets ESP traffic from that network reach the host at 10.0.0.1. Your VPN software may need more rules on top of this, so check its documentation for the rest.
The caveat is in the man page: these protocols can only be used with the full syntax. Something like ufw allow esp does not fit that rule, so spell it out with to and proto. The same goes for ah, gre, vrrp, ipv6 and igmp. They are not enabled when you leave out the protocol, and ESP, AH, GRE and VRRP rules take no port number.
Further reading: ufw man page
Going deeper: Why a Tailscale device vanishes after 180 days, and how to stop it