When you say the same subnet, are you clear about the industry definition of subnet because is a frequently baroquely mis usesd term.
I want to clarify you're saying the two OSx boxes aren't separated by a router (firewalls are routers with attitude) linking two address schemes where these boxes reside.
What you're describing is a dead ringer for stale ARP records being missed with either a nonexistent or misconfigured *strong text*ARP pruning plan., ARP is Ethernet's method of addressing that TCP/IP addresses are co-dependent on proper operation.
You're detailing one system fails to find the other until it is reached first by the same computer it just failed to find until it is updated first by the missing computer.
If this is an ARP pruning issue, the missing computer that has to ping second is updating your first and errant computer with its new ARP/IP combination, if they're both on different subnets, an industry grade switch such as a Cisco or NetGear professional device would manage these records seamlessy and prevent this from happening frequently compared to a network unequipped with such gear.
A good question to ask, is Machine B equipped with a more aggressive power management policy or less frequently used and being allowed to suspend / hibernate ? Since doing so isn't a perfect event and the Windows community has this problem on larger small company networks attempting to save money on electricity but haven't upgraded their network infrastructure. So PC's tap out, their IP addresses get leased to someone else or returned to address pool and remain unassinged. Your Machine A remains insistent Machine B must be at this particular IP address when it was long since evicted from that address.
Confirm this by preventing neither macine from suspending or turning off their NICS to conserve power, WiFi NICS typically use more power and are more aggressively managed so if these are WiFi boxes, check all the power manvger settings in both macs to esnure they remain alive and powered.
TCP/IP commands are share more common parts than other commands used in Mac/Windows, on the Win side, we use
to dump the listing of IP's and ARP's, the next time your B box is unfreachable and assuming you can reach it, visit it firstr and don't ping anyting yet to awaken anything until you determine its current IP address
Then from Machine A confirm it can't find Machine B again and execute the equivalent arp -a commanhd, comapre the IP Machine A (the box that can't B until B announces itself), if the IP's are different from A's cache and B's physical inspection... you got an ARP pruning issue and you owe me full credit for this detailed answer.