If the pH of the solution is lower than the pKa of the compound, then the compound will be protonated, because pH is a measure of the concentration of protons, and low pH means a high proton concentration, so the compound is “driven” to act as a base and take up protons because there’s so much of them in the solution. By the same logic, if pH is higher than pKa then the concentration of protons in solution is not very high, so the compound is “driven” to act as an acid and donate protons to the solution. What is the “driving” force (I know it’s not technically a force) that causes this behaviour? Is there a thermodynamic reason involving changes in enthalpy and entropy and an increase in stability (decreasing Gibbs free energy) in the system? My own thought is that perhaps this spontaneous exchange of protons between the compound and solution based on pKa and pH values takes the system closer to an equilibrium... but I don’t know where to go from there.