Cannot ping over LAN until a ping is received

When you say the same subnet, are you clear about the industry definition of subnet because is a frequently baroquely misused 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 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 seamlessly 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? Because 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 the address pool and remain unassigned. 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 both machines 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 management settings in both machines to ensure they remain alive and powered.

TCP/IP commands share more common parts than other commands used in Mac/Windows, on the Win side, we use arp -a to dump the listing of IP's and ARP's, the next time your B box is unreachable and assuming you can reach it, visit it first and don't ping anything 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 command, compare 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.