As discussed in comments the key concept here is the content or Jordan measure of a set. The discussion which follows will deal with bounded sets only and we will refrain from mentioning this explicitly.
Definition: Let $S$ be a set and $\mathcal{C} $ be a finite collection of intervals (of any nature: closed, open, half open etc) such that $$S\subseteq \bigcup\limits_{I\in\mathcal {C}} I$$ Then $\mathcal{C} $ is said to be a finite cover of $S$. The outer content of $S$, denoted by $c_o(S) $, is defined to be the infimum of sum of lengths of intervals in a finite cover of $S$.
And we start with our first key result:
Theorem 1: Let $S\subseteq [a, b] $ and let the function $f:[a, b] \to\mathbb {R} $ be defined such that $f(x) =0$ for all $x\in[a, b] \setminus S$ and $f(x) =1$ for all $x\in S$. Then $$\overline {\int} _{a} ^{b} f(x) \, dx=c_o(S) $$
To establish the result we consider any partition $$P=\{x_0,x_1,x_2,\dots, x_n\} $$ of $[a, b] $ and form the upper Darboux sum $$U(f, P) =\sum_{k=1}^{n}M_k(x_k-x_{k-1})$$ By the definition of $f$ we have $$U(f, P) =\sum_{S\cap[x_{k-1},x_k]\neq\emptyset} (x_k-x_{k-1})$$ and clearly the sum of lengths of the intervals which contains points of $S$ is not less than $c_o(S) $. Hence $U(f, P) \geq c_o (S) $ for every partition $P$ of $[a, b] $.
Our proof will be complete if we can show that for any given $\epsilon >0$ we can find some partition $P$ of $[a, b] $ such that $U(f, P) <c_o(S) +\epsilon$. By definition of outer content we have a finite cover $\mathcal{C} $ of $S$ such that sum of lengths of intervals in $\mathcal {C} $ is less than $c_o(S) +\epsilon$. The end points of the intervals of $\mathcal{C} $ which lie in $[a, b] $ together with the end points of $[a, b] $ form a partition $P$ of $[a, b] $. And clearly the sum of lengths of subintervals of $P$ which contain points of $S$ does not exceed the sum of lengths of intervals in $\mathcal {C} $ and thus is less than $c_o(S) +\epsilon $. It follows that $U(f, P) <c_o(S) +\epsilon $.
Notice that the arguments are simple primarily because the number of intervals involved here is finite.
In almost similar fashion we can define inner content of a set $S$, denoted by $c_i(S) $, as the supremum of sum of lengths of a finite number of non-overlapping intervals whose union is contained in $S$. If $S$ does not contain any intervals (eg $S=\mathbb{Q} \cap[0,1]$) then clearly $c_i(S) =0$.
If $S\subseteq [a, b] $ then one can prove with some effort that $$c_i(S) =b-a-c_o([a, b] \setminus S) $$ And we have the counterpart to theorem 1 above as
Theorem 2: Let $S\subseteq [a, b] $ and let a function $f:[a, b] \to \mathbb {R} $ be defined as $f(x) =1$ for all $x\in S$ and $f(x) =0$ for all $x\in[a, b] \setminus S$. Then $$\underline{\int}_{a} ^{b} f(x) \, dx=c_i(S)$$
A set $S$ is said to be Jordan measurable if $c_i(S) =c_o(S) $ and the common value of these inner and outer contents is called the content or Jordan measure of set $S$ and denoted by $c(S) $.
Our theorems 1 and 2 now lead us to
Theorem 3: Let $S\subseteq [a, b] $ and let a function $f:[a, b]\to\mathbb {R} $ be defined as $f(x) =1$ for all $x\in S$ and $f(x) =0$ for all $x\in[a, b] \setminus S$. Then $f$ is Riemann integrable on $[a, b] $ if and only if $S$ is Jordan measurable and in that case $$\int_{a} ^{b} f(x) \, dx=c(S) $$
Of special interest are those sets which are of content zero. Since $c_i(S) \leq c_o(S) $ a set is of content zero if and only if its outer content is zero. Due to the theorems proved in this answer it is clear that the set $D$ in current question should be of content zero.
How does one recognize sets of content zero? Well, a finite set is of content zero. Another example is mentioned in question: if a set $S$ has a finite number of limit points then $S$ is of content zero.
We can generalize a little bit here. Let $S'$ denote the set of limit points of $S$. Then $S'$ is said to be the derived set of $S$. And using induction we can say that $S^{(n)} $ is the $n$-th derived set of $S$ if $S^{(n)} $ is the derived set of $S^{(n-1)}$. A set $S$ is said to be of type $n$ if $S^{(n)}$ is non-empty and $S^{(n+1)}$ is empty. A set is said to be of first species if it is of type $n$ for some non-negative integer $n$ otherwise it is said to be of second species. It can be proved with some effort that every set of first species is of content zero. An obvious example of a set of second species is $\mathbb {Q} \cap [0,1]$.
Sets of content zero can be countable like $\{1,1/2,1/3,\dots\} $ as well as uncountable like the Cantor set.
Union of a finite number of sets is of content zero if each set in the union is of content zero. However the same can not be said in case of union of countable number of sets. This is a serious limitation while dealing with Riemann integrals as evident from the following
Theorem 4: Let $f:[a, b] \to \mathbb {R} $ be a bounded function. Then $f $ is Riemann integrable on $[a, b] $ if and only if for every $\epsilon>0$ the set $D_{\epsilon} (f) $ of points where the oscillation of $f$ is greater than or equal to $\epsilon $ is of content zero.
Since the set $D$ of discontinuities of $f$ can be considered as union $D=\bigcup\limits_{n=1}^{\infty}D_{1/n}(f)$ the above theorem says each $D_{1/n}(f)$ is of content $0$. But $D$ may or may not be so. This drawback of content forces us to look for some similar idea but one which is preserved under countable unions and leads us to the notion of measure as developed by Lebesgue.
Note: The answer above is based on the presentation given in David M. Bressoud's A Radical Approach to Lebesgue's Theory of Integration.