How to add new form field dynamically on selected change using ajax
Build form elements in buildForm() only, not in ajax callback. The ajax callback is only for preparing the ajax response. When the ajax callback is called, buildForm() has already run with the updated $form.

Your ajax response is empty. You didn't add any ajax command to it. See ajax examples how you can do this.

But in your case you don't need any code in ajax callback. It would be enough to simply return the changed part of $form in a div container.

For this put an empty container in buildForm() and move the select form element from the ajax callback to buildForm() and put it in the container, if the condition in $form_state is met:

$form['ajax_wrapper'] = [
  '#type' =&gt; 'container',
  '#attributes' =&gt; ['id' =&gt; 'ajax-wrapper'],
];

if ($form_state-&gt;getValue('level1') != false) {
        $form['ajax_wrapper']['level2'] = array(
            '#type' =&gt; 'select',
            '#description' =&gt; 'Please select level two term',
            //'#options' =&gt; $terms,
            '#attributes' =&gt; array(
                'class' =&gt; array(
                    'mycategory'
                ),
            ),
        );


And the ajax callback:

public function ajaxCallback(array &amp;$form, FormStateInterface $form_state) {
  return $form['ajax_wrapper'];


change #ajax to:

'#ajax' =&gt; [
  'callback' =&gt; '::ajaxCallback',
  'wrapper' =&gt; 'ajax-wrapper',
],