If someone with F-2 visa status comes to the US with his/her spouse then wants to get married a US citizen, or green card holder in the US, should he/she get divorced from his/her spouse? Or is it not necessary because the previous marriage was not conducted within the US?
TLDR: get a divorce.
Basically, the US (as with most countries) recognizes valid marriages from other jurisdictions that would be valid if performed by the couple in the US. Which means that same sex marriages before Oberfell would not have been recognized but are now. Marriage with minors are not recognized. Multiple simultaneous marriages are not recognized (no second or third husbands or wives).
Some common law marriages can have problems with this, as there is no record of the marriage.