If your data is not too large, a Unix shell command may be enough:
Here I create files containing your example data, assuming you really meant that it is space-separated.
cat > counts.txt <<_END_
gene_name sample_1 sample_2 sample_3
gene_1 count_1count_1 count_1
gene_2 count_2 count_2 count_2
gene_5 count_3 count_3 count_3
gene_6 count_4 count_4 count_4
_END_
cat > lengths.txt <<_END_
gene_name start end gene_length
gene_1 start_1 end_1 length_1
gene_2 start_2 end_2 length_2
gene_3 start_3 end_3 length_3
gene_4 start_4 end_4 length_4
gene_5 start_5 end_5 length_5
gene_6 start_6 end_6 length_6
gene_7 start_7 end_7 length_7
_END_
_(By the way, providing example data in such a way facilitates the task of those who try to answer your question. Have a try next time !)_
Then, I drop the first (header) line of your first table (sed 1d), I cut the first column, I pass it to grep via the standard input as a list of patterns to match (--file -), I specify that the matches must cover the whole word (otherwise, gene_1 would also match gene_12, etc.), I filter the second table and cut its third column, which contains the lengths.
sed 1d counts.txt |
cut -f1 -d ' ' |
grep --file - --word-regexp lengths.txt |
cut -f4 -d ' '
Beware that it will all break apart if there are variations in the format of your tables.