I'll assume you're talking about received emails - and not Gmail randomly appending the header when you send emails through the web interface.
The X-Originating-IP header is a "custom" header, in that it's not identified as a required field that all emails contain (compared to To, From, etc.).
Many email programs and web-based mail services such as Hotmail (Windows Live), Gmail, and Yahoo! Mail, append it and various other headers depending on how they were programmed. In the case of emails being sent from Hotmail or Gmail, it tracks the IP address of the computer the sender sent the email from.
It's been reported - but not confirmed - that those headers are used by the web-based email services to blacklist the IP address of computers that send an overwhelming amount of spam. You may also notice the
X-Originating-Email: header as well, which can also be appended by those services at times. This also helps to track down email spoofing, etc., on such services.
In the case of why you don't always see it - check to see what client the sender was using. Chances are it won't be a Gmail or Hotmail address - but another client that doesn't append the optional header, since it doesn't need to be used to deliver the actual message.
If you're looking to use the X-Originating-IP header for filtering, you may have better luck with the Received header, which may also contain the IP address.
One thing to note, is just like any other header, the X-Originating-IP header can be easily faked.