There are three issues.
- Did Jesus violate the sabbath by doing work
- Is gleaning/gathering sticks considered work
- Death Penalty
When is it OK to work on the Sabbath?
Jesus violated the Sabbath by working on it just as Rabbis violate it by working on it and Priests do as well. It is their job to work on the Sabbath, given their role as mediators and agents of God's provision.
Or have ye not read in the law, how that on the sabbath days the
priests in the temple profane the sabbath, and are blameless? Mt 12.5 KJV
You can't close the Synagogue so that the rabbi doesn't work on Saturday, that's like closing down the restaurant at dinner time so the waiter can eat. In the same way, those who mediate between man and God work extra hard on the Sabbath, violating it but remaining blameless. It has nothing to do with "being God" but "being God's priest/mediator" that requires you to work on the Sabbath and Jesus was no different from rabbis or priests in this respect, only he was able to do much more than they could.
The Sabbath is about relying on God's provision of holiness, so the reason you are banned from working is to make it clear that God alone is the one who does the work of sanctification, and human efforts play no role in it. The not working part is just a symbol of that. The Pharisees should have understood this instead of trying to sanctify themselves through their own observances of the Sabbath.
Moreover also I gave them my sabbaths, to be a sign between me and
them, that they might know that I am the LORD that sanctify them. Ezek 20.12 KJV
You shall surely observe My sabbaths; for this is a sign between Me
and you throughout your generations, that you may know that I am the
Lord who sanctifies you. (Exodus 31:13 NKJV)
Is gleaning work?
As to why picking fruit off a tree and eating is not considered work but gathering wood to make a fire to cook is considered work, the former is an example of God's provision -- God grew the fruit and you can reach out, take and eat from vines you haven't planted or tended. It is actually much better to pluck an apple from someone else's tree and eat it on the Sabbath than to eat food you prepared yourself the day before, as the latter is closer to you feeding yourself through your own works than the former. Thus eating fruit you haven't tended is an example of what the Sabbath is all about.
But what you can't do is fill your pockets to store it up to take home for later.
On the other hand, kindling a fire for cooking is considered work because the processing of the food - you do not take what God gives you to eat it, but you try to fix it up first to improve it, again suggesting that God's provision is insufficient and requires your effort to make it work. So one is work and the other isn't.
Ye shall kindle no fire throughout your habitations upon the sabbath
day. Ex 35.3 KJV
Yes, it is a fine line, as the line between grace and work is a fine line. The pharisees created so many rules that keeping the Sabbath ended up being work -- they profaned the Sabbath by converting a period of rest and trust in God's provision of righteousness ["I am the Lord that sanctifies you"] to a period of performing observances to obtain a works-based sanctification through their own efforts. And this is why Jesus reproved them so publicly.
For they [Pharisees] being ignorant of God's righteousness, and going about to
establish their own righteousness, have not submitted themselves unto
the righteousness of God. Romans 10.3 KJV
Death Penalty
Finally, the purpose of the death penalty was that it was deadly serious that you rely on God's provision completely and do not try to mix into that provision your own efforts. This is a theme that runs throughout the law:
And Nadab and Abihu, the sons of Aaron, took either of them his
censer, and put fire therein, and put incense thereon, and offered
strange fire before the Lord, which he commanded them not. And
there went out fire from the Lord, and devoured them, and they died
before the Lord. Lev 10.1-2
The moment you try to substitute your own work for God's work, or augment God's work with your own work, you come under the death penalty as it must all be completely God's work.
Thus the sabbath is all about the deadly seriousness of grace.
It really is a matter of life and death to trust in grace and to stop trying to earn it. For example, Moses striking the rock twice is an example of mixing human effort into God's provision. Once you understand why Moses getting away with murder did not keep him out of the promised land, but striking the rock twice did, you will understand what the Sabbath is about and then these questions will have clear answers.
But after that lesson is learned, there is not really a death penalty for cooking. E.g. the old testament examples were given to teach a lesson, but in practice people in Jesus day were not actually killed for walking too many steps, this was a religious debate about the true meaning of the Sabbath.
For he that is entered into his rest, he also hath ceased from his own works, as God did from his. Heb 4.12 KJV.