Why is there no Java compiler on Android?
If you have Android 5.0 (lollipop) or later, use termux. (Terminal IDE is great but only works up to android 4.*). It's on the google play store, and the source is on github.

It has an apt repository with several compilers, including ecj, the
Eclipse Compiler for Java, and is much faster than javac.

There's also golang, clang, gcc, node, python and a whole bunch of other stuff (tmux, vim, ctags, cscope, emacs, latexetc etc etc).

NB: this doesn't actually answer your "why" question, but might be helpful...