Is it moral to contact a questionnaire participant because of alarming response? For a study, we sent out a questionnaire to members of the general public. The questionnaire was containing items related to well-being and happiness, among other items that are completely related to my field (computer science). 

One respondent wrote about having suicidal thoughts because of personal issues. No signs of seeking treatment in the reply. 

The participant left their e-mail address in the field "contact me back for the results and/or further clarifications".

What is my role here as a researcher? My first thought was to contact the participant and pointing them to seeking help (maybe also providing links to their national suicide prevention programs).
I know I've read something in a research textbook about unexpected ethics problems, but I don't remember where or what it said.

I think you need to contact your ethics committee (or equivalent), preferably quickly, for guidance. If there were enough questions about welfare on the questionnaire to be likely to bring up some sort of similar response, you should probably think about pre-empting it next time and automatically including links to suitable resources. It may be that now you can send out details to all participants (those who left email addresses, or perhaps the original distribution list, depending on how participants were recruited), as a way of offering help without singling them out. If the wording of the email address field requires it (I can't quite make sense of it), you could perhaps do so together with the results of the research, or a preliminary summary of the results...