Read the man page for your shell. Somewhere in there, it will say something like: If you write a pipe, every command is executed in a subshell. What happens when you run read in a subshell? Well, let's think about what read does: It reads something from stdin, and sets a variable. A variable of what? Of the shell it is in. Which shell? The innermost subshell. So in the second version, read runs, it sets some variables, and those are promptly forgotten when read ends and the subshell with it.
In the first version, the read is in the main shell, so it sets variables of that shell, which you can then see.
The trick is to not put a naked read into a pipeline, but instead wrap the read in something. Here's my canonical use of read:
# prepare some data
# one or more lines
# each containing for example one word
# and pipe that output into a while command to process the lines
# for example
( echo foo; echo bar; echo blatz ) | \
while read myvar
do
# Now the variable will be set:
echo Hallo myvar is $myvar
done