Yes. Some caveats
1. Don't make a habit of it.
2. Be careful - if there are IRROPs, you could be redirected on another routing to that other country.
3. Will the departing country still want to see proof that you can fly (visa, passport) to Country C?