Pinging SQL Server Availability Group Listener sometimes fails
The AG1 listener is set to static IP with two IP address
  ...
  If I open a command prompt and ping AG1 , sometimes it succeeds (primary ip replies) and sometimes it fails (secondary ip address is unreachable)


Yes.  This is normal when the nodes are on different subnets.  The listener requires two separate IP addresses, only one of which is ever online.

Ping will resolve the DNS name, but will attempt to connect only to whichever IP is returned first.  The order address are returned varies based on the client's subnet, and through "DNS Round-Robin".

The current SQL Server client libraries are coded to understand that when a DNS name resolves to two IP addresses, it must try both, as only one will be online.