There are several versions of the Simpson diversity index, as explained in this website. I will focus here on this version, which I have stated slightly more precisely to clarify what the sum is over:
$$D = \sum_{i=1}^k\frac{n_i(n_i-1)}{N(N-1)}$$
Here $N$ is the total number of individuals within a habitat, and $n_i$ is the number of individuals of the $i$th of $k$ species. Note that, since $N$ is not indexed by $i$, it makes no difference whether the denominator is within the scope of the sum. We can equally write:
$$D =\frac{\sum_{i=1}^kn_i(n_i-1)}{N(N-1)}$$
The derivation of these formulae is a straightforward application of probability. If two individuals are chosen at random from the habitat, the total number of possible outcomes $O_{tot}$ is:
$$O_{tot} = N(N-1)/2$$
The division by $2$ is to avoid duplication where the same two individuals are chosen in reverse order. The outcomes of interest $O_{int}$ are those in which the chosen two individuals belong to the same species. For any one species $i$ the number of pairs $P_i$ of individuals belonging to that species is:
$$P_i = n_i(n_i-1)/2$$
To find $O_{int}$ we must sum over all species:
$$O_{int} = \sum_{i=1}^kP_i = \sum_{i=1}^kn_i(n_i-1)/2$$
Dividing $O_{int}$ by $O_{tot}$ and cancelling the divisions by $2$ yields the second of the above formulae for $D$.