Original problem
In fact, the problem itself has nothing to do with real-analysis, not even calculus. In fact, it's simply an algebra question. I wonder why don't we think from the definitions of the algebraic structures in which these fractions and polynomials are living. To use calculus, we are unnecessarily assuming the order structure "$x<y$".
\begin{align}
\frac{1}{(x-a)(x+a)}&=\frac{A}{(x-a)}+\frac{B}{(x+a)}=\frac{A(x+a)+B(x-a)}{(x-a)(x+a)} \label{eq1}\tag{1}\\
1&=A(x+a)+B(x-a) \label{eq2}\tag{2}
\end{align}
Note that \eqref{eq1} takes place in the field of fractions of polynomial $\Bbb{R}(X)$. From the very definition of fraction field
$$\Bbb{R}(X)=\left\lbrace \frac{p(X)}{q(X)} : p(X),q(X) \in \Bbb{R}[X] \text{ with } q(X)\ne0 \right\rbrace/\sim,$$
where $\sim$ denotes the equivalent relation $p_1(X)q_2(X)=p_2(X)q_1(X)$ for any $p_i(X),q_i(X)\in\Bbb{R}[X], i=1,2$, feel free to cancel out the denominators $(x-a)(x+a)\ne0$ in the integral domain $\Bbb{R}[X]$.
So we are left with \eqref{eq2} as an equality in $\Bbb{R}[X]$, which allows us to do substitutions mentioned in the question and in others answers.
- What if one has $$\frac{1}{(x-a_1)(x-a_2)\cdots(x-a_n)}=\frac{A_1}{x-a_1}+\cdots+\frac{A_n}{x-a_n}?$$
Answer: a special case of the next question
- What if one has $$\frac{r(x)}{(x-a_1)(x-a_2)\cdots(x-a_n)}=\frac{A_1}{x-a_1}+\cdots+\frac{A_n}{x-a_n}?$$ for any degree $n-1$ polynomial $r(x) \in R[X]$? (What conditions are needed are $R$? To be seen at the bottom.)
- Multiply both sides by the denominator to get an equality in the integral domain $R[X]$.
$$\begin{aligned}
r(x) =& A_1(x-a_2)\cdots(x-a_n)+\cdots+A_i(x-a_1)\cdots(x-a_{i-1})(x-a_{i+1})\cdots(x-a_n) \\
&+\cdots+A_n(x-a_1)\cdots(x-a_{n-1}) \\
=& A_1(x-a_2)\cdots(x-a_n)+(x-a_1)H(x) \quad\text{for some } H(x) \in R[X]
\end{aligned}$$
In the first step, the RHS is a sum of $n$ terms $A_i \in R$ multiplied by $(x-a_1)\cdots(x-a_n)$ without $x-a_i$. (Here $a_i \in R$.)
Substitute $x=a_1$ to kill $H(x)$ in slow motion, so that we understand what assumptions in needed for $R$.
$$
\require{cancel}
r(a_1) = A_1(a_1-a_2)\cdots(a_1-a_n)+\cancelto{0}{(a_1-a_1)H(a_1)} \label{eq3} \tag{3}
$$
Up to this stage, we have only considered $R$ as an integral domain, in which the cancellation law holds.
To make $A_1$ the subject of the \eqref{eq3}, we divide $(a_1-a_2)\cdots(a_1-a_n)$ on both sides, and such operation requires stability by division. As a consequence, $R$ needs to be field just because of the last step.
$$\bbox[2px, border: 1px solid black]{A_1=\frac{r(a_1)}{(a_1-a_2)\cdots(a_1-a_n)}}$$
Other coefficients $A_i$ can be determined with a similar argument.
(More rigorously, we are applying the Factor Theorem, which holds for any commutative rings.
$$r(x)-A_1(x-a_2)\cdots(x-a_n)=(x-a_1)H(x).$$
RHS is divisible by $x-a_1$, so as LHS. The Factor Theorem allows us to substitute $x=a_1$ on LHS and equate it to $0$.)