Perl 5, 130130 126 bytes
128124 bytes of code + 2 for -ap
flags
push@a,[map 0|$_/10,@F]}{map{$_=say map{($a[$r+1][$c]-$_&&$r<$#a?'_':$").($a[$r][++$c]-$_&&$c<@{$a[0]}?'|':$")for@$_;$c=0;$r++;say@$_}@$_;$c=0;$r++}@a
Input format is 2-D grid of space separated numbers.
Explanation
This is from a previous iteration of the code.
push@a,[map 0|$_/10,@F] # read the input, divide it by 10, and store it in a 2-D array
}{ # end the implicit while loop and start the final block
map{ # repeat this for each line
$_=($a[$r+1][$c]-$_&&$r<$#a?'_':$") # set appropriate characters to output based
.($a[$r][++$c]-$_&&$c<@{$a[0]}?'|':$") # on the given rules
for@$_; # repeat for each number on the line
$c=0;$r++; # setup row and column counters for next iteration
say@$_ # output this line
}@a