The 'short form' answer to the 'why' is that here
int[] nums = {2, 5, 9, 7};
an integer array is declared, memory allocated and initialised with 4 integer elements as shown, 2,5,7,9 .. You 'could' rewrite twoSum to declare an empty array eg
int[] tmpNums = new int[2];
which declares an integer array and allocates memory for two integers, then
tmpNums[0] = i;
tmpNums[1] = j;
return tmpNums;
.. but twoSum as it is doesn't declare an array 'up front' with which to return the required elements, so to return an array, it MUST use 'new' to create a new array
with the required memory allocation, before it can be assigned to and returned