Summary: if Bob is the genius who can easily spot the answer to Alice's question or if he's willing to dig into the work for weeks or months, what he produces is (deservedly) his work.
Copyright is about works (that is here the form of expression of the idea), not about the idea itself. In order to protect a (technical) idea, Alice needs a patent.
Also in science, you can (and are expected to) use other people's ideas. But you must properly attribute their origin.
Assuming that the answer is not entirely trivial, it qualifies as work of its own. Bob's work that is. Question/problem and answer/solution are typically considered different ideas, and often the work to get the answer/solution is considered larger than the work of identifying the question (although that shouldn't be underestimated, neither).
Alice asks a question in StackExchange (or any other site), defining her problem in detail, and Bob somehow figures out what the answer is. Instead of writing the answer, he publishes the paper himself.
Thus, he can post it on SX where he licenses the use of this per CC-BY-SA. This means, Alice when writing her paper, needs to attribute Bob properly.
Bob is free to publish his answer wherever he likes. Thus, also in a journal. Note that the answer without Alice's question may not be quite understandable, so he needs to attribute Alice for the question (which is also CC-BY-SA licensed). In addition, in a scientific paper he needs to cite Alice's question.
There's nothing wrong with a paper "A (new) solution to Alice's problem". In practice, I guess Bob could contact Alice to make a shared publication: at least in my field this could be a typical constellation of Alice Applicationexpert together with Bob Theoryspecialist. And even though Bob may be able to spot an answer, this doesn't mean he recognizes all that was behind the question.
Alice writes a technical report (not a full paper) and publishes it in her website. Bob downloads the technical report, shares it with his teammates and soon, they publish a paper based on Alice's technical report.
Here the question is what this "based on" means in detail: it may be anything from plagiarizing over derivative work, dependent work, to Bob's own work - depending on how close it is to Alice's report.
Whether derivative or dependent works violate Alice's copyright depends on the license Alice grants. If she did not specify anything, it is a copyright violation. (Plagiarized work is a bit difficult, because Alice could license her work in a way that does not require attribution by Bob - but in a scientific paper, he still needs to cite her properly. Plagiarism in science does not have the totally same meaning as wrt. copyright issues)
Side note: Many technical reports I know are actually more comprehensive than the respective paper.
Similar to (2), Alice has published a technical report in her website, defining a problem, with a first-attempt solution, which clearly can be improved. Bob, on the other hand, sees the technical report and finds a better solution. Then, publishes it. Now, Alice cannot publish her results because Bob's solution is better.
Note that Alice may be still happy even if Bob did not contact her, because Bob's paper allows her to concentrate her efforts on the application problem she wants to solve. It may also be that Alice still needs to write her paper, because Bob did not talk to her and unfortunately did not know about some implications of the question - so his answer is a good hint, but does not entirely solve the problem.
Alice spoke about the problem (or experiment) she is working on in an informal public place (e.g. cafeteria). Bob heard it, and found a way to solve the problem (or carried out the experiment she intended to). He published it in a journal.
I've tried to find solutions I need by talking/asking on conferences quite a bit. Far from anyone stealing my ideas, I typically hear that everyone would like to get informed when I find and publish a solution - meaning that noone is willing to relieve me of the work to find a solution.
In other words, in practice there's quite a barrier to this type of scooping because if Bob is not willing to cooperate with Alice, he needs to put in the effort Alice has already put in. Thus he goes for an uphill race when trying to be faster than Alice with the publication.
Also, are you seriously underestimating the amount of work that goes into preparing and actually doing an experiment? By the way, in many fields, Bob would get a much better experimental paper if he pooled his efforts with Alice and they got twice the sample size for their paper.
Again, if Bob performs his own experiment, it is his own. Then there would be two studies that more or less coincidentally show the same (well, if they actually show the same...).
Sometimes the time is "ripe" for some specific question - so this can also happen totally innocently. Scientifically speaking this is good, because experimental science nowadays has IMHO more problems due to a lack of replicate experiments than the other way round.
Again my experience is that in this case the studies will still not be quite the same.
How can Alice prove that her work was plagiarized
She needs to show that Bob copied her work without license and without proper attribution. That is, she needs to show
- Which part(s) of Bob's work are the same as hers, and
- that her work was done first.
The method that gives you best legal chances is: use a notary. That's very expensive, though. There are less expensive methods that should work in practice. E.g. if it is about the idea how to set up the experiment, Alice could show her paper lab book where she always neatly puts all her thoughts with proper date etc. Same if there's a record of a lab meeting/seminar where Alice presented her results. If it is about some part of the paper, Alice could also show when she checked these sentences into the version control server her group uses. Of course, if Bob than shows that their VC server got his sentence earlier, Alice is in trouble.