Why are activities of solids and liquids taken to be unity? First, I should mention that the question was already asked here: Why is active mass of a pure solid or liquid always taken as unity?
However, the treatment there is qualitative and I do not really understand the reasoning for the disclusion of solids and liquids from the reaction qoutient that is presented there. I have attempted to derive this fact mathematically and failed, which why I ask this question again.

Let us look at an example reaction which involves solids and gases. The treatment for other reactions or reactions with liquids shouldn't differ significantly. A very simple reaction for this matter will be the combustion of graphite

$$\ce{C(s) + O2(g) -&gt; CO2(g)}$$

Reaction quotients are derived from the equation for change in Gibbs free energy at nonstandard pressures, so let's find that. Suppose the reaction is carried out in nonstandard pressure, and $\Delta G^o_r$ is known. Let's (I) compress the system isothermally to standard pressure, (II) carry out the reaction and then (III) return it isothermally to the original pressure.

I. $\Delta G$ for the oxygen here is the well known $RT\ln (1/(P/P_o))$. For the carbon: In any isothermal process $dG=VdP$, let's assume for our ideal solid that the volume is constant (I have also tried this in a model where the volume changes with pressure with bulk moduli, the result does not differ significantly), so $\Delta G=V(P-P_o)$.

II. Here simply $\Delta G=\Delta G^o_r$.

III. Here it's just gas compressing so again $\Delta G=RT\ln (P/P_o)$

Adding the contributions from all three stages we have
$$
\Delta G=RT\ln (1/(P/P_o))+V(P-P_o)+\Delta G^o_r+RT\ln (P/P_o)=\Delta G^o_r+V(P-P_o)
$$

This result is different from what a model of an activity of unity for the carbon would predict. What went wrong? And why are activities of solids and liquids taken to be unity? Any help will be appreciated.
It is not that case that the activity of solids and liquids is always taken as unity.  

Instead, activity is unity for a pure solid or pure liquid at standard pressure.

This is a matter of definition of "activity" and "standard state".

According to the IUPAC definitions: 

activity (relative activity), a


  Defined by the equation
  $a=e^\frac{\mu-\mu ^0}{RT}$
  where $R$ is the gas constant, $T$ the thermodynamic temperature, $\mu$ the chemical potential
  and $\mu ^0$ the standard chemical potential the definition of which depends on the choice of the standard state.


and standard state


  State of a system chosen as standard for reference by convention. Three standard states are recognized: For a gas phase it is the (hypothetical) state of the pure substance in the gaseous phase at the standard pressure p = p °, assuming ideal behaviour. For a pure phase, or a mixture, or a solvent in the liquid or solid state it is the state of the pure substance in the liquid or solid phase at the standard pressure p = p ° ...


So activity is 1 almost by definition when a substance is in its standard state, because $\mu - \mu ^0 = 0$  and $e^0 = 1$