The comments above seem to have picked up the general gist of things with Z-Moves, which is that they're very situational. Whilst they're not entirely useless and there are several Pokemon that benefit greatly from it, many of them are gimmicks and are rarely a more consistent option than simply using a Life Orb, Choice item, Leftovers, etc.
With that said though, some Pokemon can successfully run sets with Z-Moves. To directly answer your question as to when it is a good idea to use Z-Moves, oftentimes they will be used to provide a helpful STAB move that would otherwise be ineffective or too weak. For example, I've seen numerous Landorus-T sets that choose to use the move Fly and the Flyinium Z item to use Supersonic Skystrike, which can allow Landorus to blow past Pokemon that are bulky or resistant to Earthquake. In addition to this, using Flyinium Z has some other perks for Landorus -- the first is the surprise factor. One may be tempted to switch in Grass-type Pokemon to absorb an Earthquake, but you can punish that using a strong STAB Flying move, something Landorus would never run otherwise since Fly is such a poor competitive move. You don't even need to predict the switch; if your opponent isn't expecting the Flyinium Z, you can just use Earthquake as a safe midground play in case they don't switch, then follow into Supersonic Skystrike if they do attempt to wall you.
Salamence is Pokemon that can make similar use of the move Fly thanks to Flyinium Z; it lends it a powerful nuke attack to hit Fairy-type Pokemon that resist its main Dragon attack. Kartana finds use for Fightinium Z on Sacred Sword for a similar reason -- it allows it to break past many Pokemon that can withstand its mediocre STAB offensive coverage (Grass/Steel). It should be noted that for Pokemon like these, Z-Moves have become quite common, so you may miss out on some of that surprise factor you might get on other Pokemon.
Though Z-Moves becoming popular on some Pokemon can remove the surprise factor and mean teams are better prepared, you can still bluff your item until you eventually reveal the Z-Move you have. In the same situation with Landorus, if the opponent doesn't see a Rocky Helmet, Life Orb or a Leftovers on your Pokemon, they will almost always assume that you are using Choice item. (Leftovers is basically announced at the end of each turn, and Rocky Helmet and Life Orb are made very obvious when you start using attacks.) However, like Choice items, Z-Crystals are not easily revealed to your opponent like the aforementioned items often are, which means you can surprise your opponent with a strong Z-Move if they think they can wall a Choice-locked Pokemon. This follows on to the other major use for Z-Moves, which is to provide Pokemon with a powerful additional coverage move, allowing it to function as a sort of lure. For example, if your opponent sees no obvious item on a Heatran, they may assume that it is using Scarf or Specs and expect to wall its move. However, if you use Solar Beam and Grassinium Z, you could punish a Water- or Ground-type switch attempting to wall you. The function of this particular Heatran set would be to lure in those Water- and Ground-type Pokemon and knock them out to open an opportunity for it or a teammate to sweep the opponent; as such, it is still quite situational, as you only need it if those types of Pokemon are a particularly large problem to your team.
Status Z-Moves tend to be the most gimmicky and situational of all of them; generally you won't find a lot of uses for them. Things like Z-Splash might be good in theory, but they're thoroughly outclassed by moves like Swords Dance that don't take up an item slot, and in Z-Splash's case, aren't completely useless after one use. If you are to use them, once again it's often for the surprise factor. A notable exception to this is the wildly popular Z-Conversion set for Porygon-Z, which effectively changes its subpar pure Normal typing to a different one of your choosing and boosts all of its stats, turning it into a very scary sweeper that you must play carefully against at all times. Another one that that could be useful is Z-Memento, which I've seen used on Pyukumuku in particular. This has Memento's usual effects and fully heals your replacement Pokemon. The move is great to build momentum (which is when your Pokemon counters your opponent's and your opponent therefore has to make a defensive play, which you can predict) and to set up a sweep you may not have been able to otherwise; it also means you can allow your win condition to take damage since you can heal it back later.
If you're still figuring out Z-Moves in the meta, my best advice is to just avoid them unless they will allow your Pokemon to KO a threat that you struggle against otherwise, or if the move will allow your Pokemon to break past a substantially higher amount of Pokemon (Porygon-Z is its own category). It's also worth noting that offensive Z-Moves are almost always used on set-up sweeping Pokemon or win condition Pokemon, along the occasional lure like Grassinium Z Heatran. As mentioned, most of the time your normal competitive staple items like Life Orb, Leftovers, Choice items, etc. are better simply becuase they're more consistent and play more to the Pokemon's strengths instead of forcing them to counter something awkwardly. (As in, you couldn't switch Heatran into a Ground-type Pokemon even if you are running Bloom Doom on it, because that's way too risky unless the Pokemon is expendable.)