If someone with F-2 visa status comes to the US, then wants to marry with a US citizen/green card holder, should he/she ends/gets divorce of his/her previous wife/husband even if their marriage happened outside of the US and they both aren't US citizens/green card holders?
US laws generally prohibit a marriage if either person is currently in a valid marriage to a third person, whether in the US or anywhere else. If a current marriage is valid it must be ended by divorce or in some other way before a valid US marriage can occur. Marrying in the US while already married to another person is the crime of bigamy, and will also render the later marriage invalid and void.
All this is true regardless of immigration status, it would be true for citizens, green-card holders, holders of any visa type, and undocumented people. No one may contract a marriage while currently married to someone else.
I believe this is true in all US states and territories.
Committing the crime of bigamy could possibly have negative impact on the immigration status of a non-citizen, in addition to potential criminal penalties.
I am not sure why you would think it might be OK to proceed with such a marriage without first obtaining a divorce, annulment, or other lawful termination of any existing marriage, inside or outside the US, but it is not.