Understanding the connection between pH and EC is helpful. Although pH is fundamentally related to the potential hydrogen ions, it nonetheless gives you a base idea of the amount of cations in relation to anions (the balance of charge), if you will, this is called "base saturation". At a perfect pH of 7, there will be 100% filled cation sites in the direct medium. Once you know what nutrients are anions and which are cations, you can judge more or less when it's time to "lime up" when the pH gets low. When the pH is 7.0 or higher, the binding sites on your soil or media colloids are functionally 100% occupied by "base" (alkaline) cations: Ca2+, Mg2+, K+, Na+.
Soil pH itself is a.............hydrogen ion concentration (balance of charge) held within the soil's liquid solutions (medium). This concentration of water + salt ions creates an EC (electrical conductivity)
EC is the main driver of osmosis, so your job is to maintain an optimal EC for this to occur.
EC is a combination of two metrics, salt ion concentration and water(moisture) concentration.
The Electrical Conductivity of a plant medium fluctuates continuously with the wet-dry cycle because water acts as the solvent for nutrient salts. As the medium dries out, the water evaporates, compressing the same amount of salts into a smaller volume of liquid. This causes the EC to spike.
"Under what conditions should I be testing soil pH? Is there a specific time of day? Before watering or after?"
Test your soil or medium just before your next scheduled watering. This captures the most stable environment for both pH and Electrical Conductivity. Look after your EC going in & out. If the pH ratio going in is good, then the pH by default in the medium is good, if you apply it correctly to run off. When you use synthetic delivery of nutrients, all you are essentially doing is replacing old salts with new salts, making sure the EC of the direct medium stays within a range. You need to make sure you wash out old salts with correct % run off or unused salts from previous waterings can accumulate, skewing the pH balance.
Water is always in the mornings, perfect soil composition comes nightfall, so long as you take your readings at roughly the same timeframe its not really a big deal. Generally speaking, most growers don't actually measure the direct EC of the soil itself; they use TDS to gauge the EC going in and the EC runoff coming out, so reading pH is tied to feed/waterings. You can also buy a metre and keep tabs on your EC at all times, but this will fluctuate all over the place as your medium dries and salts are used/released. It's less about when and what time and focuses more on consistency, either right before watering or when the medium is at a moderate moisture level. Consistency brings baselines.
Most problems occur for new growers when people mix synthetic nutrient delivery with organic nutrients.
Sorry for the long babble. If most of that is gobbledegook, then:
"Under what conditions should I be testing soil pH? Is there a specific time of day? Before watering or after?"
Wrong question. Look after your EC going in & out, if you do that correctly, pH can't go wrong if you are using synthetic nutrient delivery alone.
Organic growers generally don't track pH so long as there is a large enough buffer zone, the rhizosphere takes care of pH and changes the chemical profile to attract different bacteria based on what nutrients it needs the most, using the soil food web and the plant's natural intelligence rather than micromanaging soil pH.
Good luck in the quest for frosty buds!