If someone with a F-2 visa comes to the US with her F-1 spouse, then they apply for EB2-NIW green card (with the F-1 visa holder as the primary applicant and F-2 visa holder as his dependent), then can they still qualify for and get their green cards? And after that they get a divorce, what will happen to the wife who was the dependent of the applicant throughout the procedure? Will her Green Card expire and she must leave the US?
Nothing happens. Once she becomes a US permanent resident (i.e. green card holder), her status is not dependent on anyone else's status, nor on her relationship with anyone else. She can remain a permanent resident forever, renewing her card as many times as she wants, and she can apply for naturalization if and when she qualifies and is willing to.
(This, of course, assumes that the marriage was not fraudulent, i.e. they didn't enter the marriage to circumvent the immigration laws).