Lynn Starkey worked at Roncalli High School in Indianapolis for nearly 40 years. In May, however, the Roman Catholic school fired Starkey as a guidance counselor after officials discovered that she is married to a woman.

In July, Starkey, 63, sued the school and the Archdiocese of Indianapolis, claiming, in part, that they discriminated against her on the basis of her sexual orientation.

Lynn Starkey is suing a Roman Catholic high school and the Archdiocese of Indianapolis after she was fired as a guidance counselor because she is married to a woman. Delaney and Delaney LLC

In May, the school's principal notified Starkey, who has been married to her spouse since 2015, that her contract would not be renewed, stating in a letter that civil unions are in violation of her contract and “contrary to the teaching of the Catholic Church.”

The archdiocese — which is also being sued by a gay teacher who was recently fired from a different Catholic school in Indianapolis — claims that it has a “constitutional right to hire leaders who support the schools’ religious mission.”

"Catholic schools exist to communicate the Catholic faith to the next generation," the archdiocese said in a statement sent to NBC News. "To accomplish their mission, Catholic schools ask all teachers, administrators and guidance counselors to uphold the Catholic faith by word and action, both inside and outside the classroom."

The issue of gay educators being fired by or excluded from employment at religious schools is not new, and since 2014, several cases have come before the courts. It’s also not unique to Indianapolis or Catholic institutions. In January, Karen Pence, the vice president's wife, said she would return to teaching at a Christian school at Virginia that refuses to hire LGBTQ employees or to educate LGBTQ students.

So, is this legal? While the majority of Americans across all religious groups support employment nondiscrimination protections for LGBTQ people, according to a recently released PRRI public opinion poll, the law is less straightforward.

“The law is in flux,” said Jenny Pizer, law and policy director for Lambda Legal, an LGBTQ civil rights organization. “There are some principles we are sure of and some that are still being developed and sorted out in the courts and state and federal legislatures.”

In order to understand the rights of lesbian, gay, bisexual, transgender and queer workers employed by religious organizations, one must consider both federal and state law, the Constitution and executive orders.

Federal Law

Title VII of the 1964 Civil Rights Act prohibits employers from discriminating on the basis of race, color, religion, sex and national origin. However, it contains “multiple overlapping exemptions” when it comes to religion, according to Marcia McCormick, a professor of law and gender studies at Saint Louis University.

For one, any employer can discriminate on the basis of religion if religion is considered necessary for the exercise of the job, McCormick explained. For example, a Kosher butcher shop may want to hire only Jewish butchers.

Religious schools can discriminate in hiring in some circumstances. “They get singled out as getting this one provision that talks about schools being able to discriminate if the curriculum is directed toward the propagation of a particular religion,” McCormick said. A school run by Southern Baptists that seeks to encourage more people to convert to the faith could, according to this section of Title VII, hire only Southern Baptists.

Other kinds of religious organizations are also allowed to prefer co-religionists in their hiring — a Catholic charity is allowed to prefer Catholics in the hiring process. However, while religious organizations have leeway when it comes to hiring people of their own faith, they are not supposed to discriminate on the basis of other protected characteristics like sex, race or national origin, McCormick explained.

“That is where there is a big potential clash,” she said, adding that the issue for LGBTQ workers is twofold.

“Title VII has an expansive definition of religion — not just of beliefs but also practices,” she explained. “There are a lot of rules in a lot of religions about how people ought to behave when it comes to what it means to be male and female, or to sexual or romantic activity.”

Then, she added, there is the issue of the definition of “sex” in Title VII. If it is interpreted to include sexual orientation and gender identity, then LGBTQ workers can seek employment protection under federal civil rights law. They have done so in many cases, but the circuit courts are split on the issue. Luckily for Starkey, Indianapolis is covered by the 7th U.S. Circuit Court of Appeals, which has ruled in the case of Hively v. Ivy Tech Community College that sex discrimination encompasses discrimination on the basis of sexual orientation.

The Supreme Court, however, is scheduled to take up three cases this year that could have a major impact on LGBTQ workers’ nondiscrimination protections.

Title VII’s Ministerial Exception

In Starkey’s case, the archdiocese appears to be drawing on what is called the ministerial exception to Title VII under the First Amendment, which guarantees free exercise of religion.

In 2012, the Equal Employment Opportunity Commission sued an evangelical Lutheran church and a school in Michigan on behalf of a former employee, Cheryl Perich, a “called” teacher that underwent theology training and was considered to be in a ministerial position. Perich was diagnosed with narcolepsy and took disability leave as a result. When she was ready to return the work, the church told her she no longer had a job. The EEOC lost the case before the Supreme Court.

Pizer said this case “validated the ministerial exception, which lower courts had said existed but the Supreme Court had not spoken to." The exception applies only to employees serving a ministerial function, but it affords the religious employer tremendous protection against claims of discrimination.

Maggie Siddiqi, director of the Center for American Progress’ Faith and Progressive Policy Initiative, told NBC News that in recent cases, employers are claiming that many different types of employees serve ministerial functions.

“That is really expanding the definition beyond its original intent,” which can “open the door for discrimination against all of these employees," Siddiqi said.

Religious Freedom Restoration Act

An individual or a business may also claim protections under the 1993 Religious Freedom Restoration Act, a federal law that prohibits the government from discriminating on the basis of religion.

RFRA comes up in the case of R.G. & G.R. Harris Funeral Homes Inc. v. Equal Employment Opportunity Commission, one of the three LGBTQ workers’ rights cases currently before the Supreme Court. The case involves Aimee Stephens, a transgender woman who was fired from a Detroit funeral home after she informed her employer that she was beginning her gender transition.

In district court, the funeral home claimed that to employ Stephens violated the owner’s sincerely held religious beliefs, and for the EEOC to compel him to employ Stephens was an overreach of government authority in contravention of the Religious Freedom Restoration Act. The Circuit Court sided with Stephens, but the Supreme Court will have the last word in the matter.

State Law

In the absence of a federal law that explicitly protects workers from anti-LGBTQ discrimination, a worker can seek redress in state law. Twenty-one states and the District of Columbia have passed measures prohibiting discrimination based on sexual orientation and gender identity, according to the Movement Advancement Project, an LGBTQ think tank. Three additional states offer some form of LGBTQ workplace protections.

However, more than 20 states — including some of those with explicit state-level LGBTQ worker protections — have religious freedom laws or religious exemptions to their nondiscrimination protections. Indiana, where Roncalli High School is, has such a law. In fact, in 2015, then-Gov. Mike Pence signed Indiana’s Religious Freedom Restoration Act, which spawned significant criticism by those who said it would open the door to anti-LGBTQ discrimination.

Executive Orders & Department Rules

In 1965, President Lyndon B. Johnson signed Executive Order 11246 barring federal contractors who do over $10,000 of business with the government in one year from discriminating on the basis of race, color, religion sex or national origin. In 2002, President George W. Bush issued an executive order that added a religious exemption to the measure, using language lifted from Title VII. In 2014, President Barack Obama added sexual orientation and gender identity to the list of protected characteristics in Johnson’s original order, affording specific protections to LGBTQ workers, but Obama left intact Bush’s protections for religious organizations.

At the beginning of his presidency, Donald Trump vowed not to touch the nondiscrimination protections of LGBTQ workers in Obama’s executive order. However, he has issued a subsequent executive order that LGBTQ advocates argued undermine the efficacy of Obama’s measure.

In 2017, then-Attorney General Jeff Sessions issued "religious liberty" guidance that elaborates principles such as “religious employers are entitled to employ only persons whose beliefs and conduct are consistent with the employers’ religious precepts.”

Since then, many government departments under the Trump administration have followed suit, including the Department of Health and Human Services, which has proposed their own religious freedom rules to be overseen by a new Conscience and Religious Freedom Division.

This month, the Department of Labor released its own proposed rule expanding religious exemptions available to government contractors and sparking outcry from many LGBTQ advocates. The rule expands the types of organizations eligible for exemptions to “employers that are organized for a religious purpose, hold themselves out to the public as carrying out a religious purpose, and engage in exercise of religion consistent with, and in furtherance of, a religious purpose,” and also allows employers to “condition employment on acceptance of or adherence to religious tenets without sanction by the federal government, provided that they do not discriminate based on other protected bases.”

The Trump administration claims that religious organizations need extra protections from nondiscrimination law, because not having them prevents these organizations from seeking federal contracts.

“It’s not just that they are changing a rule,” Pizer said regarding the impact of the rule, “but the way the change is being done is an explicit signal that this administration favors religious interests over the equality interests of LGBT people and women.”

What's Next?

The Supreme Court will hear three cases in October that are expected to have a considerable impact on LGBTQ workers’ rights. Two of the cases deal with sexual orientation, the other with gender identity. In the meantime, the Department of Justice made clear in briefs filed this month that LGBTQ workers should not be covered by Title VII protections. In doing so, the DOJ puts itself at odds with the EEOC and the majority of Americans.

Democrats in Congress have responded by reintroducing the Equality Act, a piece of federal legislation that would add sexual orientation and gender identity to the list of classes protected against discrimination by the Civil Rights Act of 1964, and does not allow religious exemptions to civil rights law under Religious Freedom Restoration Act.

Follow NBC Out on Twitter, Facebook & Instagram