Why does my code or Serial Monitor hang with analogRead?
Arduino UNO have 2K RAM (many other too). That is 2048 bytes of RAM. 

I suppose, that analogVals[] is declared as int and having 1000 entries it takes 2000 bytes of RAM, leaving wholesome 48 bytes for all your others variables (including int i in the for cycle and Serial outside it) and stack for calling functions (like analogRead and sq) and all theirs variables and functions and arguments. 

So int i = 2B, Serial = 2B, sumOfSquares = 2B, "Sum of squares: " = 17B of what I see takes anothe 23 bytes of those 48 bytes leaving us with only 25 bytes for all else.

I bet, that you try to use more REAM, than you have and so your stack overflows and 


destroys some variable content on the vay
is overwriten by assigning to some variables, which then leads to all sort of problems.