G-4s are not typical nonresidents. It’s not the G-4 visa that makes you a nonresident. It’s the fact that you are a full-time employee of an international organization. As such, your workdays do not count as physically present in the United States for the Substantial Presence Test of US residency, so you are a nonresident. However, you live in the US (>183 days), so in most cases, your “tax home” will be in the US. This is why you are taxable on your capital gains.