Logically speaking, why can variables be substituted? Suppose that
$$a^2+a+1=b$$
Suppose also that $a=5/4$. What makes it valid to substitute $5/4$ into the first equation? Is it because equality is transitive?
 A: The reason why you can make such a substitution is that $a$ and $\dfrac{5}{4}$ are precisely the same, just written differently. Here's a long-winded way of making the substitution you describe.
\begin{align*}
a &= \frac{5}{4} & \\
a^2 &= \left(\frac{5}{4}\right)^2 &\text{squaring both sides}\\
a^2 + a &= \left(\frac{5}{4}\right)^2 + \frac{5}{4} &\text{adding the first two lines}\\
a^2 + a + 1 &= \left(\frac{5}{4}\right)^2 + \frac{5}{4}+1 &\text{adding $1$ to both sides}\\
b &= \left(\frac{5}{4}\right)^2 + \frac{5}{4}+1 &\text{using the fact that $a$ satisfies the given equation}
\end{align*}
The right hand side is precisely what you obtain when you replace $a$ by $\dfrac{5}{4}$.
A: It's just a basic principle of first-order logic with equality that if $a = b$ and $P(b)$ for a formula $P$, then $P(a)$. It's probably the most important aspect of equality that usually "goes without saying" in mathematics, except in logic courses. 
A: There are at least two ways to understand equality.
One way to treat it is as a primitive logical identity sign: $a=b$ means that ‘$a$’ and ‘$b$’ are signs for the same thing.  Since they represent one and the same object, any property that can be proved of the object represented by $a$ must also hold of the object represented by $b$, because they are the same object. In this case one automatically gets a general substitution principle: $a$ can be replaced by $b$ because they mean the same thing: they are names for the same object.
Another way to proceed is the way that ZF set theory does, and to take equality as a defined property.  For example, ZF says that ‘$a=b$’ is an abbreviation for $$\forall x(x\in a\iff x\in b).$$
Two sets are defined to be equal if they contain the same elements.  If one does this, substitution must be asserted axiomatically, or proved as a theorem.  Without such a proof (trivial if substitution is an axiom) it might or might not hold. Transitivity is similar.
But the usual understanding in algebra is the first type: when we write something like ‘$x = \frac54$’ we mean that the name ‘$x$’ is a synonym for whatever object is denoted by $\frac54$. 
