  The lowest order Josephson coupling, $J_1(\theta)\cos(\phi)$, between two
d-wave superconductors with phase-difference $\phi$ across the junction
vanishes when their relative orientation is rotated by $\theta=\pi/4$. However,
in the presence of inhomogeneity, $J_{1}(\mathbf{r})$ is non-zero locally, with
a sign that fluctuates in space. We show that such a random $J_1$ generates a
global second-harmonic Josephson coupling, $J_2\cos(2\phi)$, with a sign that
favors $\phi = \pm \pi/2$, i.e., spontaneous breaking of time reversal
symmetry. The magnitude of $J_2$ is substantially enhanced if the spatial
correlations of $J_1(\mathbf{r})$ extend over large distances, such as would be
expected in the presence of large amplitude twist-angle angle disorder or
significant local electronic nematicity. We argue that this effect likely
accounts for the recent observations in twisted Josephson junctions between
high temperature superconductors.
