When reading the story of Purim as recorded in the Book of Esther (the Megillah), it is important to understand that the authors had to be extremely careful with their words and account of events—considering that the Jews were still under Persian rule. Undoubtedly, the Persians powers-that-be would get a hold of a copy of the Megillah. As such, many aspects of the Purim story – specifically those that would reflect badly on the king or empire – were included in a very veiled manner. Only in later generations was the full story transcribed in the Talmud, various midrashim, and commentaries.
Esther did not want to be taken to the palace. Not only was she an upright Jewish girl who abhorred the notion of marriage to a Gentile vile king, she was actually already married! The Talmud explains that she was married to Mordechai, her cousin, who was also the greatest sage of that generation.
Every time Esther was taken to Ahasuerus, she was literally taken and forced to be with him. Throughout her "marriage" to Ahasuerus, Esther still remained loyal to her true husband, Mordechai. After leaving Ahasuerus' presence she would immerse in a mikvah and then secretly rendezvous with Mordechai.
So, to get back to your question of how she could marry a non-Jew—it was not her choice, but rather something that she was forced to do. Had she refused to comply with the king's wishes, she would have been put to death. (Remember that Ahasuerus had already ordered his previous wife's execution in a fit of drunken rage.)1
That, in a nutshell, is why she was able to continue living in the palace.
See also Is a Jew required to die rather than disobey a Torah command?
I hope this clarifies the issue,
Chana Weisberg for Chabad.org