How to add rows to a form table with AJAX Callback in Drupal 8
Details and Warnings
  
  Changes to the form must only be made in the form builder function
  (ajax_example_autocheckboxes() in the example here), or validation
  will fail. The callback function must not alter the form or any other
  state.


Reference: https://www.drupal.org/docs/7/api/javascript-api/ajax-forms-in-drupal-7

It's for D7, but the concept how Ajax works has not changed:


  The Big Idea 
  
  The big idea here is that:
  
  
  Your form gets rebuilt when you manipulate a form element (e.g. select, submit etc.)
  Your form builder function builds it a different way based on that input ($form_state)
  Your #ajax settings and your callback function arrange to deliver all or a part of the newly rebuilt form to replace or otherwise
  enhance some part of the page.