Physically, the moment of inertia is basically a rotational form of regular translational inertia. Newton's 2nd law (\(F = ma\)) describes how masses are accelerated due to forces, but mass can be seen as a resistance to acceleration. In that way, more mass is more resistant to being accelerated. For translations, \(F=ma\) describes this. For rotations, \(T = J \alpha\) is the equivalent.

The inertia tensor (matrix) describes in essence how "hard" any object is to be rotated about some point and some axis. To calculate it, you choose a reference point (can be on or off the body, but we like using either the centroid or center of mass), choose reference axes (can be arbitrary but should be a right-handed basis at least), break the objects up into small, infinitesimal pieces, and then calculate the moment of inertia of each piece, then sum them up (usually in a kind of weighted average fashion). This is why integrals are usually present in the matrix formulation. The inertia matrix is useful when you are rotating in 3D and not necessarily along an axis of the reference frame from which you calculated the matrix (i.e. not rotating about the X, Y, or Z axis).

However, a lot of times the objects of which you want the moment of inertia are easily broken down to more simple geometric forms that can be easily calculated. In your capsule example, they are breaking down the capsule into cylinders and spheres, something easily more calculable than using the integral method. We can use do a similar thing as above by calculating the moments of inertia of each geometric piece and summing them up with a kind of weighted average. If we are summing up the moments of inertia in this way, our "weighted average" is the parallel axis theorem. The parallel axis theorem allows us to calculate the moment of inertia of an object and compensate for the distance that object is away from the rotation axis. We can see this by spinning a pencil about its middle or about its ends. It's "harder" to spin about the ends than about the middle because the bulk of the pencil's mass (or we can also say the center of mass) is much farther away from the rotation axis. The parallel axis theorem gives us the correct adjustment factor to sum things up this way.

You labeled the cylinder and sphere terms correctly, but the "what's this for" is the term due to the parallel axis theorem by moving the half-spheres out away from the rotation axis, which is directly in the middle of the capsule. They seem to have combined the half-sphere moment of inertias and the parallel axis theorem transfer terms in the code.

Hope that helps!