PHP Fatal error: Smarty error: [in string: (...)]: syntax error: (secure mode) (...) not allowed in if statement (...)
There is a surprisingly simple solution:
Smarty assumes, that comparison containing a constant string is unsafe.
A remedy is, to assign the constant value to a variable, and to perform the comparison between these two variables.
The code example from above could look like:
{capture assign=gift}{contact.custom_16}{/capture}
{capture assign=Yes}Yes{/capture}
{if $gift == $Yes}
  This membership is a gift from {contact.custom_17}.
{/if}

Good luck!