Ethics in the practice or use of mathematics is often addressed indirectly by mathematicians. Below I give three examples that come to mind, the first expounded in more detail than the others (because it is less obvious).

In a not always direct way V. I. Arnold often wrote about ethics in mathematics. By way of illustration, I quote a bit from the beginning of his article [Topological problems of the theory of wave propagation][1]:

> The difference between pure and applied mathematics is not scientific
> but only social. A pure mathematician is paid for uncovering new
> mathematical facts. An applied mathematician is paid for the solution
> of quite specific problems. 
> 
> **Example**. Columbus began by making a purely applied study, trying to find the way to China, and he was being paid for this. 
>
> The end of his voyage is reminiscent of a fact of pure mathematics. Note that the immediate direct benefit to the Spanish economy of the discoveries of Columbus was far less than that from the coastal navigation of ordinary captains. 
>
> Mayakovsky has well described the difference between pure and applied mathematics in "How to make poetry". "The man who found that twice two is four was a great mathematician even if he found it out by counting cigarette stubs. Those who now calculate by the same formula much greater things, for example locomotives, are not mathematicians at all." 
>
> The theory of algebraic curves over finite fields has now become applied mathematics,
financed by the CIA, the KGB and other similar organizations. Fermat's
problem would also be applied if its solution were of monetary value. Many mathematicians of the twentieth century have warned of the dangers of dividing mathematics into parts. Hermann Weyl has written: "In our time the angel of topology
and the devil of abstract algebra are fighting for every mathematical domain" [1].
>
> ...
> 
> Generations of mathematicians were taught by this method, not having any
contact at all with any other kind of mathematics. As a result they cannot understand
any other science and enthusiastically busy themselves with tedious details
of generalizations of achievements of their teachers of little interest.

Although, as is apparent from the cited text, Arnold's affirmations about history and culture were frequently questionable, when not outright wrong, to focus on this is to miss the point of the cited text, which is to use the history as a cartoon to illustrate an ethical/social claim about the practice of mathematics. I do not here try to summarize what I think the claim is, in part because the cited text is taken out of its context in a larger text, and in part because Arnold's intentionally polemical and ironical writing style was well adapted to expressing his ideas succinctly, if not always transparently. (I recommend reading the article to see what his point was and whether one agrees with it.) 

This sort of passage is by no means isolated in Arnold's writing. Many of his essays, particularly in his later years, contain similar commentaries. So does the introduction to his book on geometrical methods in ordinary differential equations, whose statement
> The axiomatization and algebraization of mathematics, after more than
50 years, has lead to the illegibility of such a large number of mathematical
texts that the threat of complete loss of contact with physics and
the natural sciences has been realized.

is well known. That this statement is part of a basically ethical commentary seems to me clear, as it self-evidently is in the following passage from the above cited article:
> It is clear, however, that the writer does not understand anything, but only knows
how to prove. The absurdity and even the criminality of a system of education,
leading clearly intelligent people to such a state, seems to me to be obvious. For
'applied' work such 'knowledge' is useless and even dangerous (the consequences
may take on the character of a Chernobyl disaster).
>
> The aim of a mathematical lecture should be not the logical derivation of some
incomprehensible assertions from others (equally incomprehensible): it is necessary
to explain to the audience what the discussion is about and to teach them to use
not only the results presented, but—and this is major—the methods and the ideas.

Arnold's writings of this style are often (partly unfairly) considered merely a (misguided) attack on Bourbaki (although there is some of this in them) and this can distract from what was a coherent point of view enunciated repeatedly over many years. It would be interesting for someone interested in such matters to try to distill in nonpolemical terms the essential ethical content of that commentary. I have my own idea, but it's not scholarly, and I don't feel able to express it well in a forum like this, although I will comment that I think my own learning process suffered from precisely what Arnold criticizes and as the years have gone by I have adjusted how I try to research and teach accordingly, although often unsuccessfully.

I think examples of similar writings by other mathematicians can be found, particularly among those who came of age during the cold war in the countries it most afflicted (e.g. USA and USSR) and had direct contact with the use of mathematics in contexts related to defense, warfare, and spying. 

Doron Zeilberger posts on his webpage "[Opinions][2]", many of which have an ethical character, in particular with respect to the questions of how to do mathematics and what constitutes good mathematics.

The "[Bible codes][3]" episode generated writings by mathematicians having an ethical character.

If one broadens the context from "mathematics" to the "mathematical sciences" then there is much more written, often of a more explicitly ethical character. I have in mind something like Andrew Gelman's [blog][4], which frequently, as do Gelman's articles, addresses ethical questions related to the use and practice of statistics. There are many more examples.


  [1]: https://doi.org/10.1070/RM1996v051n01ABEH002734
  [2]: https://sites.math.rutgers.edu/~zeilberg/OPINIONS.html
  [3]: https://www.math.toronto.edu/~drorbn/Codes/
  [4]: https://statmodeling.stat.columbia.edu/