For that to happen, you need to do two things:
- Peer the two VNets together.
- Create an NSG rule that only allows those two VMs to communicate with each other; no other VMs should be able to communicate to the other VNet.
On the rule, for PING (ICMP) to work, you need to also allow ICMP for the Virtual Machines to be able to ping each other.
If it's still not working, if it's on Windows, try disabling the Windows Firewall as this may be blocking the ping request or create an exception by just enabling ping (ICMP).