I am applying for some PhD programs, and I don't know if I should mention my country's situation in those letters, like the difficulty in being a female scientist without having a friend at court or free speech problems in my country.
It’s generally okay to mention it, and any person with a heart is going to feel sympathy for your situation. But it’s important that you understand that this will have zero effect on your chances of getting admitted to most PhD programs. The only possible exception is in disciplines where your background of being from a country where there is a lack of free speech and women aren’t treated well is relevant for the discipline you want to study. For example, if you applying for a PhD in political science or human rights law and want to cite your background to explain why you have the passion to study those topics, this would be a helpful narrative that could actually make an impression on the admissions committee.
But for most topics, admission is based on merit and potential to succeed in the program. If you are applying for a PhD in math, say, I suggest focusing on why you have the passion and talents to succeed in your studies in this area rather than on why you want to move to a different country, which, although it is obviously important to you, would have no relevance to your ability to succeed in a PhD program. Good luck!
You need to be careful in how you phrase it.
In some ways, a PhD application is similar to a job application. You need to convince people that you are the best person for the position.
After reading your application, you want the application committee to remember you as "the super-qualified candidate whom we'd love to have in our PhD program, because it will be pure pleasure to do research with them", not as "the poor person who'd take any position just to get out of their terrible country". I'm not saying that the latter is the case, I'm just warning that you might create this impression if you get the wording wrong.
If possible, present it as a hardship you overcame (and which, therefore, speaks for your character), not as a reason to have pity with you.
I agree with @DanRomik's answer and would like to add one exception:
One case in which mentioning it would be advisable is if you apply to work with a particular advisor (which is generally the case in Europe), and that advisor indicates an interest in working with students that come from challenging background. That indication could be a statement on their website, a membership in a particular mentorship cycle, relevant tweets, or likewise.
This ultimately hinges on whether there is some aspect of the application where this information would be relevant. Some application processes will ask you to write a personal statement, or ask what attracts you to the institution you are applying for, or ask you to specify if you have encountered hardships in your previous work. In all these cases the culture and professional limitations in your home country might potentially be relevant and you could mention them. Ultimately, you will need to judge whether those details are germane to any part of the application process for the position in question.
I think it is good to mention it. I have never seen such statements in PhD applications (I am in math and in the USA) but I would, as a member of hiring committee, consider such applications favorably. I think that just mentioning the name of the country is not enough. It is important that you personally care about these issues.
(Decided to upgrade this from a comment to answer)
Whenever you bring up political/ideological issues like what you describe, you need to be careful, because if you reach someone with the opposite politics/ideology it can backfire.
female scientist without having a friend at court
If you're applying to an Afghan university, this will not work well.
Note what looks uncontroversial to you might still be controversial to people you've never met. For example,
free speech problems
As I mentioned in the comments, I know people who think free speech is a bad idea and semifree speech is the right thing. For example, they support the national security law in Hong Kong because Hong Kong is part of China and it is natural to restrict speech that promotes secession; furthermore Hong Kong will become a full part of China in 28 years, so gradual restrictions are sensible. If you live in Hong Kong and write about free speech in your PhD application, and you reach someone who believes this, it can backfire. To quote a more loaded example:
in most left-leaning universities arguing that you would really like to move to the US because the US, unlike your European home, allows you to buy a semi-automatic weapon with relative ease, is neither a convincing reason for a move nor will it strike brownie points on an emotional level with many faculty members.
There are motivated, intelligent people in every country of the world.
There are many countries, though, in which it's much harder to study and travel abroad if you're a woman. It's stupid and counter-productive, but that's the way it is.
This fact can be used by recruiters from other countries: if you're a woman coming from a misogynistic culture and you apply for a PhD, it means that you probably have faced adversity, but did not give up.
You don't need to explicitly mention the difficulty in being a female scientist in your country, but you can hope that recruiters will connect the dots.