What is the right level of generality for $(R/a) \times (R/b) \cong (R/\gcd(a,b)) \times (R/\operatorname{lcm}(a,b))$? Let $R$ be a principal ideal domain. Let $a$ and $b$ be two elements of $R$. Let $g$ be a greatest common divisor of $a$ and $b$, and let $\ell$ be a least common multiple of $a$ and $b$. (Of course, each of $g$ and $\ell$ is unique up to associates.)
Using prime factorization and the Chinese Remainder Theorem, it is not hard to see that

\begin{align}
\left(R/a\right) \times \left(R/b\right) \cong \left(R/g\right) \times \left(R/\ell\right) \qquad \text{ as $R$-algebras}
\label{eq.darij1.1}
\tag{1}
\end{align}

(where $R/r$ is shorthand for the quotient algebra $R/\left(rR\right)$ whenever $r\in R$).
If $g = 1$ (so that $a$ and $b$ are coprime), this is an instance of the well-known isomorphism $\left(R/a\right) \times \left(R/b\right) \cong R/\left(ab\right)$ that follows from the Chinese Remainder Theorem. This latter isomorphism can be described explicitly, as soon as we know two elements $x,y\in R$ satisfying $xa+yb=1$; indeed, it sends each pair $\left(\overline{u}, \overline{v}\right)$ to $\overline{ybu+xav}$, and its inverse sends each $\overline{r}$ to the pair $\left(\overline{r},\overline{r}\right)$.
I'm struggling to find a similarly explicit description of the isomorphism \eqref{eq.darij1.1}, even assuming that $x,y,p,q\in R$ are given such that $g = xa+yb$ and $a = pg$ and $b = qg$ and $\ell = pqg$. In fact, I think this kind of data is not enough, because if it was, then we could probably replace the requirement that $R$ is a PID by the weaker requirement that $Ra+Rb$ is a principal ideal, but that weaker requirement is insufficient for the isomorphism \eqref{eq.darij1.1} to exist (e.g., let $R = \mathbb{Z}\left[x\right]$, $a = 2x$, $b = 3x$, $g = x$ and $\ell = 6x$).
However, I can imagine various constructions that could work around this hurdle (e.g., taking further gcds). So I'm wondering:

Question. What is the most general (not-too-artificial) setting in which the isomorphism \eqref{eq.darij1.1} exists? What is the most natural way to construct it?

Note that if we lower our sights and ask for an $R$-module isomorphism $\left(R/a\right) \times \left(R/b\right) \cong \left(R/g\right) \times \left(R/\ell\right)$, then we can easily find an explicit isomorphism using matrix algebra. Namely, picking $x,y,p,q\in R$ such that $g = xa+yb$ and $a = pg$ and $b = qg$ and $\ell = pqg$, we have the matrix transformation
\begin{align*}
\begin{pmatrix}
a & 0 \\
0 & b
\end{pmatrix}
& \overset{C}{\to}
\begin{pmatrix}
a & xa \\
0 & b
\end{pmatrix}
\overset{R}{\to}
\begin{pmatrix}
a & xa+yb \\
0 & b
\end{pmatrix}
=
\begin{pmatrix}
pg & g \\
0 & qg
\end{pmatrix}
\overset{C}{\to}
\begin{pmatrix}
0 & g \\
-pqg & qg
\end{pmatrix} \\
&
\overset{R}{\to}
\begin{pmatrix}
0 & g \\
-pqg & 0
\end{pmatrix}
\overset{R}{\to}
\begin{pmatrix}
-pqg & 0 \\
0 & g
\end{pmatrix}
\overset{C}{\to}
\begin{pmatrix}
pqg & 0 \\
0 & g
\end{pmatrix}
=
\begin{pmatrix}
\ell & 0 \\
0 & g
\end{pmatrix}
\end{align*}
(where $\overset{R}{\to}$ means an elementary row transformation, and $\overset{C}{\to}$ means an elementary column transformation), and therefore we conclude that $\left(R/a\right) \times \left(R/b\right) \cong \left(R/g\right) \times \left(R/\ell\right)$ as $R$-modules because congruent matrices have isomorphic cokernels. But I don't believe that this isomorphism will respect multiplication.
I have a hunch that Dedekind domains might have a role to play here.
 A: Note that unlike the canonical map $R/(I \cap J) \stackrel\sim\to R/I \times R/J$ of the Chinese remainder theorem (whenever $I+J=R$), your isomorphism relies on a choice: for each prime $\mathfrak p$ with $v_{\mathfrak p}(a) = v_{\mathfrak p}(b) > 0$, you have to pick which factor of $(R/a)_{\mathfrak p} \times (R/b)_{\mathfrak p}$ goes into $R/g$ and which into $R/\ell$. This is a good reason why there isn't a super neat formula, but let's see what we can do still. (Since these choices are local, you may as well work in any Dedekind scheme, but I will mostly focus on the PID setting, to avoid further complications.)
One necessary condition is that $V(I)\amalg V(J) \to V(I \cap J)$ has a section (which is what goes wrong in your example). Dedekind schemes have the fortuitous property that the subschemes supported at a closed point are totally ordered by inclusion (this is equivalent to the statement that the local ring is a valuation ring), which guarantees existence of such a section in full generality. As you showed, already on a 2-dimensional regular scheme this is no longer the case.
Returning to the PID case, just like the formula for the inverse of $R/(I \cap J) \stackrel\sim\to R/I \times R/J$ by finding inverses $yb$ and $xa$ of $(1,0)$ and $(0,1)$ respectively, there is also a tautological way to 'compute' a map as in your question. If $a = pg$ and $b = qg$ as in your notation, any $R$-module homomorphism $\phi \colon R/a \times R/b \to R/g \times R/\ell$ will be of the form
$$(u,v) \mapsto \big(ru+sv,yqu+xpv\big)$$
for some $r,s,x,y \in R$. For $\phi$ to send $(1,1)$ to $(1,1)$, we need $r+s=1$ and $xp+yq=1$ (equivalently, $xa+yb=g$). It is then multiplicative if and only if $rs \equiv xy \equiv 0 \pmod g$: this is clearly necessary as $\phi(1,0) \cdot \phi(0,1) = (rs,xypq)$, and then check that it is also sufficient using $r+s=1$ and $xp+yq=1$.
Solving $xp+yq=1$ is standard using the Euclidean algorithm. Then all other solutions are given by $(x+nq)p+(y-np)q=1$, and we want to solve $(x+nq)(y-np) \equiv 0 \pmod g$. It seems to me that solving this already involves the Chinese remainder theorem for $g$, and as noted above there could be many solutions (to be precise, $2^{\lvert S\rvert}$ where $S = \{\mathfrak p\ |\ v_{\mathfrak p}(a)=v_{\mathfrak p}(b) > 0\}$).
Example. If $a=12$ and $b=18$ (so $g=6$, $p=2$, and $q=3$) and we chose $x=-1$ and $y=1$, then we need to solve
$$(-1+3n)(1-2n) \equiv 0 \pmod 6.$$
Solving this modulo $2$ and modulo $3$ gives congruence conditions on $n$, but at $2$ we need to use the first factor $(-1+3n)$ and at $3$ we need to use the second factor $(1-2n)$. This gives the conditions $n \equiv 1 \pmod 2$ and $n \equiv -1 \pmod 3$, so for instance $n=-1$ works, replacing $(x,y) =(-1,1)$ with $(x,y)=(-4,3)$.
So at this point I think you might as well go ahead and compute all components separately: for each prime power dividing $g$, solve the above congruence, giving explicit $x$ and $y$.
I don't know a neat criterion for injectivity (equivalently, surjectivity) of $\phi$, but it seems to be the case that finding explicit $x$ and $y$ already involves local computations. Then you can proceed by checking at each prime that the two components of $\phi$ (which simplify to the first or second coordinate projection after tensoring everything with $R/{\gcd(a,b,\mathfrak p^\infty)}$) do not agree.
