Both patterns are in use across a wide variety of applications, so there's no definitive answer. Most operating system menus have settled on graying out invalid options, so absent any other consideration you might want to follow their lead.
Consider your users. Are they employees (aka a captive audience?) They may be trained and adapt more rapidly to hiding options than the general public.
Will hiding invalid options cause the remaining options to reshuffle themselves across the screen? That may cause problems for people who expect the same option to always be in the same position; but it may not make much difference if it's on a pop-up menu.
Will hiding the invalid options free up so much real estate that the remaining options all now fit on a single screen? Eliminating scrolling widgets could greatly simplify the interface.
Also be aware that grayed-out options occasionally lead to user frustration. The user may be halfway through a screen and really wants to select delete, but if the option is grayed out and unresponsive, the user may struggle trying to solve that issue; wasting time before looking for other options like finding a cancel button.