Please explain to me the meaning of the quote, "Freedom and slavery are mental states."
This is something Mahatma Gandhi said and its context is:
The moment the slave resolves that he will no longer be a slave, his fetters fall. He frees himself and shows the way to others. Freedom and slavery are mental states. Therefore, the first thing is to say to yourself; ‘I shall no longer accept the role of a slave. I shall not obey orders as such, but shall disobey them when they are in conflict with my conscience.’
Gandhi was the leader of the Indian movement for independence from British rule. He advocated the use of non-violent techniques and he strongly influenced Martin Luther King, Jr.'s leadership of the Civil Rights movement in the U.S.
A person's physical context may have little or nothing to do with their psychological context. Humans have the opportunity to choose responses to others, including those who would be oppressive. All the authority in the world cannot stop each individual from making this choice. People can obey oppressive authority or we can respectfully choose not to obey it.
There are many good historical examples of individuals making this choice. For example, resistance against Hitler and the Nazis rose quickly in Europe and a significant number of people chose not to obey the Nazis. In the U.S., those who ran the "Underground Railroad" and thus freed slaves opted to break laws both in the north and the south in order to set people free.
Later, during the Civil Rights movement in the U.S., Rosa Parks continued to sit where she was on a bus despite a driver ordering her to the back. She did not act oppressed; she acted as though she had the freedom and ultimately her actions in concert with the actions of others, won that freedom.
In China, Nien Cheng was imprisoned during the Cultural Revolution but she chose how she responded to her captors. For example, instead of reading Mao's Little Red Book, she would reconstruct in her mind poetry she had learned as a young person. Her mind was free even if her body was captive.
The human mind is powerful and can transcend the worst of circumstances. Human beings have to keep remembering that there is a choice: we can cooperate with oppression or choose to be free. That is what Gandhi meant.