A function definition requires a single compound command as its body. This is legal
sum() for i in $@; do ((tot += 4)); echo $tot;done
because your for loop is that single compound command. As soon as you try to add another command (in this case, the assignment to tot), you need to ensure both that command and the for loop are combined in another compound command.
The usual way to define a function is to always use a brace group (or in certain situations, a subshell (...)), even if the only command inside the brace group is another compound command. Here, the brace group allows you to add your assignment statement to the body of the function:
sum () {
tot=0
for i in "$@"; do ((tot += 4)); echo "$tot"; done
}
Your first two attempts are errors because a single assignment statement is not a valid function body.
Your third attempt is an error because compound commands (unlike simple commands) cannot be preceded by a variable assignment.
Your fourth attempt is syntactically legal; it defines a function sum that sets the value of tot to 0. The for loop is executed after the function is defined, rather than being part of the function definition.