Can I use someone’s answer from a StackExchange site in my publication (journal paper)?
You should consult the Stack Exchange Network Terms of Service and read through the section 3. Subscriber Content which concerns rights of the material posted on the site.
I will specifucally reiterate the following

In the event that You post or otherwise use Subscriber Content outside of the Network or Services, with the exception of content entirely created by You, You agree that You will follow the attribution rules of the Creative Commons Attribution Share Alike license as follows:

You will ensure that any such use of Subscriber Content visually displays or otherwise indicates the source of the Subscriber Content as coming from the Stack Exchange Network. This requirement is satisfied with a discreet text blurb, or some other unobtrusive but clear visual indication.

You will ensure that any such Internet use of Subscriber Content includes a hyperlink directly to the original question on the source site on the Network (e.g., https://stackoverflow.com/questions/12345)

You will ensure that any such use of Subscriber Content visually display or otherwise clearly indicate the author names for every question and answer so used.

You will ensure that any such Internet use of Subscriber Content Hyperlink each author name directly back to his or her user profile page on the source site on the Network (e.g., https://stackoverflow.com/users/12345/username), directly to the Stack Exchange domain, in standard HTML (i.e. not through a Tinyurl or other such indirect hyperlink, form of obfuscation or redirection), without any “nofollow” command or any other such means of avoiding detection by search engines, and visible even with JavaScript disabled.



Apart from the specific points in the Stack Exchange Terms of Service, normal courtesy and etiquette involves always providing credit where credit is due. Even if someone posted information saying it is free for all to use, it would be appropriate to at least acknowledge the contribution by that person. In the (I assume) hypothecial case you describe in your post, contacting the person would seem like the best approach. First off, it is better to be safe than sorry, Second, by contacting the person you can avoid misconceptions or misunderstandings to accompany the post into your work and the integration fo the original idea into your work can improve. If the person upon your contact says, run with it, then fine but then you know.
So apart from avoiding to break the stated rules it is always good to contact the source and be open about the intended work or use if you work on material to be publically available through publication or otherwise.