What's the purpose of the two different definitions used for limit?
This is a very interesting question, and has quite a subtle answer, part of which has already been mentioned in some replies. I will try, to the best of my ability, to make matters clearer. To make things simpler, I will only deal with real-valued functions of real variable, though everything holds in a general topological setting.
According to Definition 2, a function $f:D\subseteq \mathbb{R} \to \mathbb{R}$ is said to have limit $b$ when $x$ goes to $a$, if $$ \forall_{\epsilon >0} \exists_{\delta >0} \forall_{x\in D} \; 0<|x-a|<\delta \Rightarrow |f(x)-b|<\epsilon . $$
Suppose first that $a$, as you put it, is an adherent point to $D$, i.e. $a\in \overline{D}$. It is quite easy to show that if $a$ is an isolated point, the limit is not unique. Indeed, consider the function $I :D=\{ 0\} \to \mathbb{R}$, defined by $$ I (x)=x. $$ Then for all $\epsilon >0$, all $x\in \{ 0\}$, all $\delta >0$ and all $b\in \mathbb{R}$, we have that $$ 0<|x-0|<\delta \Rightarrow |I(x)-b|<\epsilon $$ is vacuously true, and so $I$ tends to every single real number whenever $x$ goes to $0$. This is definitely not good!
A simple workaround is to make the definition solely for accumulation points, rather than adherent points. (Recall that $a$ is said to be an accumulation point of $D$ if every (open) neighbourhood of $a$ contains a point of $D$ other than $a$ itself). In such case, our poor function $I$ would go from having every single limit possible to having no limit at all whenever $x$ goes to $0$. Strange, but not outrageous.
To see why this workaround leads to issues, we have to dig slightly deeper into the theory. Consider, for instance, the definition of continuous function, as defined by Heine. A function $f:D\subseteq \mathbb{R} \to \mathbb{R}$ is said to be continuous at a point $x_0 \in D$ if $$ \lim_{x\to x_0} f(x) = f(x_0), $$ and is said to be continuous if it is continuous at every point of its domain. In particular, the limit has to exist, and consequently the function $I$ is not continuous at $0$. Even stranger, but still not outrageous.
From here onward, though, the theory quickly crumbles if one is not careful, as well-known "theorems" may suddenly become false statements. Take, for example, the following result:
If $h:H\subseteq \mathbb{R} \to \mathbb{R}$ and $g:G\subseteq \mathbb{R} \to \mathbb{R}$ are two continuous functions, then $g \circ h : \{ x\in H: h(x) \in G \} \to \mathbb{R}$ is continuous.
Take then, for instance, $h(x) = -x$ and $g(x)=\sqrt{x}$, both defined on $\mathbb{R}^{+}_{0}$ and continuous. Then $g\circ h = I$, which we have seen not to be continuous. Oops!
Naturally, these problems ultimately boil down to how carefully definitions are laid out on top of one another. As a counter-argument to this specific example, some authors only define the composition of functions whenever (abusing notation a bit) $h$'s codomain is a subset of $g$'s domain. Others require $h$'s codomain to be equal to $g$'s domain. In both these cases, the example above wouldn't work.
In the end, you just have to be very careful, but I would definitely recommend you using Definition 1 :)
I can't say what the purpose of the different definitions is, and as to why the different definitions are used in different books, for the more recent books I can only offer the guess that authors tend to use the definitions they learned when they were young. (I was raised on definition 1, but am also entirely comfortable with definition 2.)
However, it's not unusual that two different definitions of a concept are widely used (is $0 \in \mathbb{N}$ or not, does $\subset$ mean the same as $\subseteq$ or as $\subsetneq$, are neighbourhoods by definition open or not, are topological vector spaces Hausdorff by definition or not, are compact spaces Hausdorff by definition or not). Typically, all widely used definitions are in some circumstances more convenient than the others, and in other circumstances less convenient.
For the case of the two widely used definitions of $\lim\limits_{x\to a} f(x)$, without much thinking I can list:
- Definition 1 is better behaved with respect to composition of functions. If $f\colon A \to B,\, g \colon B \to C$ and $\lim\limits_{x\to a} f(x) = b$, $\lim\limits_{y\to b} g(y) = c$, then with definition 1, one has $\lim\limits_{x\to a} (g\circ f)(x) = c$, whereas with definition 2, this last limit need not exist (if $g(b) \neq c$ and $f$ attains the value $b$ in each neighbourhood of $a$).
- Definition 1 works also for isolated points of the domain.
- Definition 2 is nicer in the many situations when one wants to exclude the point $a$ (the value $f(a)$) from the considerations, e.g. for derivatives, $f'(a) = \lim\limits_{x\to a} \frac{f(x) - f(a)}{x-a}$; with definition 1, one needs to write $\lim\limits_{\substack{x \to a \\ x \neq a}}$ in these situations.
If you can think of other situations where one definition is more convenient than the other, you are invited to add these to the list.
Here is supplementary information showing that actually both definitions are in use. I have to admit, since I am familiar with definition $2$ (punctured neighborhood) the definition $1$ looks rather weird to me.
In fact definition 1 violates two principles which I usually associate with the term limit:
The idea behind $\lim_{x\rightarrow a} f(x)$ is not to tell us anything about $f$ at $x=a$ but instead about $f$ near $x=a$.
The limit $\lim_{x\rightarrow a} f(x)$ depends on the set of points in $x\in D$ and does not change its behavior if the limit point $a\in D$ or $a\in \overline{D}\setminus{D}$.
Here is a small illustration to the second point. Let us consider a function $f$ defined on $0\leq x <1$ with $f(x)=1$ if $0<x<1$ and $f(0)=2$.
We obtain according to the different definitions \begin{array}{ll} \text{definition }1\qquad&\qquad\text{definition }2\\ \hline \lim_{x\rightarrow 0}f(x)\quad\not\exists\qquad&\qquad\lim_{x\rightarrow 0}f(x)=0\\ \lim_{x\rightarrow 1}f(x)=0\qquad&\qquad\lim_{x\rightarrow 1}f(x)=0\\ \end{array}
In fact when going through some analysis books I found both kinds of definitions.
Some references of definition 1 and 2
Introduction to Calculus and Analysis by Richard Courant
In section 1.8: The Concept of Limit for Functions of a Continuous Variable we can read
[Courant] ... Expressed more precisely the definition of $\lim f(x)$ is as follows.
Whenever an arbitrary positive quantity $\varepsilon$ is assigned, we can mark off an interval $|x-\xi|<\delta$ so small that for any $x$ which belongs both to the domain of $f$ and to that interval the inequality $|f(x)-\eta|<\varepsilon$ holds, then \begin{align*} \lim_{x\rightarrow \xi}f(x)=\eta \end{align*}
It's interesting that the definition does not that clearly state a punctured neigborhood. This is different to the german version where this book is based upon:
Vorlesungen über Differential- und Integralrechung vol. 1 by R. Courant
[Courant]... Genauer ausgedrückt besagt die Bedingung:
Zu jeder beliebig kleinen positiven Zahl $\varepsilon>0$ können wir ein Intervall $|f(x)-\eta|<\varepsilon$ finden, so daß für jeden Punkt $x$ dieses Intervalles und $x\ne \xi$ die Ungleichung $|f(x)-g|<\varepsilon$ gilt.
He continues explicitly pinpointing why $x\ne \xi$ is required: Namely to apply the definition also in cases where $f(x)$ is not defined at $x=\xi$.
[Courant] Hier schließen wir ausdrücklich $x=\xi$ aus, um die Definition auch dann anwenden zu können, wenn $f(x)$ by $x=\xi$ nicht definiert ist.
$$ $$
Lehrbuch der Analysis vol. 1 by Harro Heuser
In section $38$ Stetigkeit und Grenzwerte von Funktionen (continuity and limits of functions) the author clearly addresses definition 2 by explicitly pinpointing the usage of a punctured neighborhood:
(p. 236) Wir betonen noch einmal sehr nachdrücklich, daß man bei de Untersuchung der Frage ob $\lim_{x\rightarrow\xi}f(x)$ existiert und wie groß er ggf. ist, den Punk $\xi$ nicht zu betreten braucht, ja gar nicht betreten darf.
$$ $$
Analysis 1 by Otto Forster.
Otto Forster introduces the concept in chapter 10 based upon definition 1.
$$ $$
Principles of Mathematical Analysis by Walter Rudin
Walter Rudin on the other hand sticks on definition 2. It is stated as definition 4.1 in section ch. 4 continuity in the section Limits of functions. He explicitly writes
[W. Rudin, p. 84] It should be noted that $p\in X$, but that $p$ need not be a point of $E$ in the above definition. Moreover, even if $p\in E$, we may very well have \begin{align*} f(p)\ne\lim_{x\rightarrow p}f(x) \end{align*}
$$ $$
Undergraduate Analysis by Serge Lang
Serge Lang takes definition 1. He introduces it in ch. 2 Limits and Continuous Functions, section 2 and he uses an example similar to mine above to introduce the concept of definition 1.
He also cautiously states that this type of definiton is not the only one. We can read
[S. Lang, p. 44] The conventions adopted here seem to be the most convenient ones. The reader should be warned that occasionally, in some other books, slightly different conventions may be adopted.
Finally a short summary of pros for definition 1 and pros for definiton 2:
Definition 1: O. Forster - S. Lang
Definition 2: R. Courant - H. Heuser - W. Rudin