How are the Tate-Shafarevich group and class group supposed to be cognates?
As a preliminary remark, note that the Tate-Shafarevich group also measures a certain defect, just like the class group. Its elements correspond to homogeneous spaces that have points everywhere locally but no global points. This is explained e.g. in Silverman.
First, let us agree that the Birch and Swinnerton-Dyer conjecture is the elliptic curves analogue of (the square of!) the analytic class number formula. Just like the latter, the former gives an algebraic interpretation of the central value of the $L$-function associated with a Galois representation (in fact a compatible family of $l$-adic Galois representations). See this MO post for more on the comparison of these two formulae.
In both formulae, a central role is played by a certain finitely generated abelian group. In the class number formula, it's the unit group of the ring of integers, in the BSD formula it's the Mordell-Weil group. Both formulae contain the size of the torsion subgroup in the denominator, and the volume (to be precise the covolume under a suitable map) in the numerator. Also, both contain some Tamagawa numbers. In the class number formula, we can only see the Tamagawa numbers at the infinite places, in the guise of some powers of 2 and $\pi$. Finally, both contain the discriminants of the number fields involved. The only other ingredient is the class number in the one case and the size of sha in the other. It is therefore natural to conclude that these "correspond to each other" in these two situations.
There is in fact a more precise correspondence, but one that is much harder to explain. Both formulae have a common generalisation, the Bloch-Kato conjecture. Under this generalisation, sha and the class number literally become the same object attached to a motive. In particular, the class number can, just like sha, be expressed in terms of Galois cohomology. This is explained in some surveys on the Bloch-Kato conjecture and on its equivariant refinement, but even the surveys have quite a lot of prerequisites in order to be able to read and to understand them.
Just as a small addition of an example where the Tate-Shafarevich group and the ideal class group are related. Developing the arithmetic of Pell conics (which are affine curves of genus 0 and degree 2 motivated by Pell's Diophantine equation: $x^2+pxy-dy^2=1$ where $p\in\{0,1\}$), a corresonding Tate-Shafarevich group $Ш(\mathcal{P}/\mathbb{Z})$ can be defined and Lemmermeyer proves that it is isomorphic to the square of the narrow class group of binary quadratic forms of discriminant $\Delta=p+4d$ (because the Pell conic can be equivalently defined by $X^2-\Delta Y^2=4$). Since the theory of binary quadratic forms is intimately related to quadratic field extensions, we arrive at the following isomorphism with the narrow ideal class group of such field extension: $$Ш(\mathcal{P}/\mathbb{Z})\cong \operatorname{Cl}^{+}(\mathbb{Q}\sqrt{\Delta})^2.$$ In particular, Hambleton obtains a cohomological definition of the Tate-Shafarevich group of Pell conics analogous to the usual definition of elliptic curves, i.e. as the kernel of a homomorphism between cohomology groups of Pell conics: $$Ш(\mathcal{P}/\mathbb{Z})\cong \operatorname{ker}\left(H^1(G,\mathcal{P}(\bar{\mathbb{Z}})) \rightarrow H^1(G,\mathcal{P}(\bar{\mathbb{Q}}))\right),$$ checking that it is well defined to be used as the starting definition.
Let me elaborate on your mentioning that the class group measures the obstruction to unique factorization. These results on Pell conics make the whole subject fascinating because historically the introduction of ideal numbers and finally ideals in quadratic number fields, and the crucial definition of their (narrow) equivalence to get the class group, was motivated by the (proper) equivalence of binary quadratic forms, i.e. forms representing the same integers. This is because there is a bijection, in fact a group isomorphism, between proper classes of such quadratic forms and narrow classes of ideals in the ring of integers of quadratic fields, given by the fact that those ideals are generated by two elements in this case and thus have a naturally associated quadratic form; then requiring two ideals to generate equivalent quadratic forms leads us to the definition of equivalent ideals. All this makes ideal class groups and class numbers (and their finer narrow counterparts) a central topic in algebraic number theory: the ideal class group of a general number field is an obstruction to unique factorization of its integers because it measures how many non-principal non-equivalent ideals are needed to recover unique factorization. In modern expositions the treatment via fractional ideals obscures sometimes the original motivation and meaning (i.e. that $h\neq 1$ is an obstruction is clear, but what does it actually count?). This approach makes algebraic number theory wonderfully and tightly tied together after studying class field theory, where a major theorem is the existence of the Hilbert class field, that any number field $K$ always has an extension $E/K$ such that its degree is the class number, $[E:K]=h_k$, the ideal class group is isomorphic to the Galois group $\operatorname{Cl}(K)\cong\operatorname{Gal}(E/K)$ and that every ideal of its algebraic integers $\mathcal{O}_K$ is principal in the ring extension $\mathcal{O}_E$. This means that we can see our original approach fulfilled since this means that the non-principal ideals of $\mathcal{O}_K$ can be correctly seen as the multiples of algebraic integers "outside" of $K$ but in $E$.
Thus, the Tate-Shafarevich group serves again as a bridge between classical algebraic numbers and modern arithmetic geometry, like Alex mentions in his answer because of its role in generalizing the class number formula via BSD. For more on the arithmetic of Pell conics as an introduction to number theory, check out the book in progress by Lemmermeyer and his other articles:
- Lemmermeyer - Pell Conics, an Alternative Approach to Elementary Number Theory.
One has (ignoring the contribution of the infinite places) $Ш(A/K) = \mathrm{H}^1_\mathrm{et}(\mathcal{O}_K,\mathscr{A})$ and $\mathrm{Cl}(\mathcal{O}_K) = \mathrm{H}^1_\mathrm{et}(\mathcal{O}_K,\mathbf{G}_m)$.