Given this action decides if a game was ultimately won or lost how does the following resolve;

Magician is insaneas an action he closes the Kingsport gate"transported" to the church and gains sanity backso he doesn't have to play the relic card he's holding.

next investigator plays the relic card (requires 1 less clue card to close next gate)we win the game

or

Magician is insaneplays the relic card first (requires 1 less clue card to close next gate)he closes the Kingsport gate with four cardsmoves to church and gains sanity backultimately the investigators don't have enough Dunwich clue cards before the player deck expireswe lose the game

It's the first option you list above. The Magician must use a Relic he has in his possession at some point on his turn if he is insane. Since he clears himself of insanity first, he no longer is required to use the Relic. The flexibility was kept in the card so that players can do exactly what you listed above.

This type of wording clarification will be added to the future FAQ for sure.