(22) If, then, you faithfully keep all this Instruction that I command you, loving the LORD your God, walking in all His ways, and holding fast to Him,
(יט) הַעִידֹ֨תִי בָכֶ֣ם הַיּוֹם֮ אֶת־הַשָּׁמַ֣יִם וְאֶת־הָאָרֶץ֒ הַחַיִּ֤ים וְהַמָּ֙וֶת֙ נָתַ֣תִּי לְפָנֶ֔יךָ הַבְּרָכָ֖ה וְהַקְּלָלָ֑ה וּבָֽחַרְתָּ֙ בַּֽחַיִּ֔ים לְמַ֥עַן תִּחְיֶ֖ה אַתָּ֥ה וְזַרְעֶֽךָ׃ (כ) לְאַֽהֲבָה֙ אֶת־ה' אֱלֹקֶ֔יךָ לִשְׁמֹ֥עַ בְּקֹל֖וֹ וּלְדָבְקָה־ב֑וֹ כִּ֣י ה֤וּא חַיֶּ֙יךָ֙ וְאֹ֣רֶךְ יָמֶ֔יךָ לָשֶׁ֣בֶת עַל־הָאֲדָמָ֗ה אֲשֶׁר֩ נִשְׁבַּ֨ע ה' לַאֲבֹתֶ֛יךָ לְאַבְרָהָ֛ם לְיִצְחָ֥ק וּֽלְיַעֲקֹ֖ב לָתֵ֥ת לָהֶֽם׃ (פ)
(19) I call heaven and earth to witness against you this day: I have put before you life and death, blessing and curse. Choose life—if you and your offspring would live— (20) by loving the LORD your God, heeding His commands, and holding fast to Him. For thereby you shall have life and shall long endure upon the soil that the LORD swore to your ancestors, Abraham, Isaac, and Jacob, to give to them.
(ג) עֵֽינֵיכֶם֙ הָֽרֹאֹ֔ת אֵ֛ת אֲשֶׁר־עָשָׂ֥ה ה' בְּבַ֣עַל פְּע֑וֹר כִּ֣י כָל־הָאִ֗ישׁ אֲשֶׁ֤ר הָלַךְ֙ אַחֲרֵ֣י בַֽעַל־פְּע֔וֹר הִשְׁמִיד֛וֹ ה' אֱלֹקֶ֖יךָ מִקִּרְבֶּֽךָ׃ (ד) וְאַתֶּם֙ הַדְּבֵקִ֔ים בַּה' אֱלֹקֵיכֶ֑ם חַיִּ֥ים כֻּלְּכֶ֖ם הַיּֽוֹם׃
(א) אֵ֣ת כָּל־הַדָּבָ֗ר אֲשֶׁ֤ר אָנֹכִי֙ מְצַוֶּ֣ה אֶתְכֶ֔ם אֹת֥וֹ תִשְׁמְר֖וּ לַעֲשׂ֑וֹת לֹא־תֹסֵ֣ף עָלָ֔יו וְלֹ֥א תִגְרַ֖ע מִמֶּֽנּוּ׃ (פ) (ב) כִּֽי־יָק֤וּם בְּקִרְבְּךָ֙ נָבִ֔יא א֖וֹ חֹלֵ֣ם חֲל֑וֹם וְנָתַ֥ן אֵלֶ֛יךָ א֖וֹת א֥וֹ מוֹפֵֽת׃ (ג) וּבָ֤א הָאוֹת֙ וְהַמּוֹפֵ֔ת אֲשֶׁר־דִּבֶּ֥ר אֵלֶ֖יךָ לֵאמֹ֑ר נֵֽלְכָ֞ה אַחֲרֵ֨י אֱלֹקִ֧ים אֲחֵרִ֛ים אֲשֶׁ֥ר לֹֽא־יְדַעְתָּ֖ם וְנָֽעָבְדֵֽם׃ (ד) לֹ֣א תִשְׁמַ֗ע אֶל־דִּבְרֵי֙ הַנָּבִ֣יא הַה֔וּא א֛וֹ אֶל־חוֹלֵ֥ם הַחֲל֖וֹם הַה֑וּא כִּ֣י מְנַסֶּ֞ה ה' אֱלֹֽהֵיכֶם֙ אֶתְכֶ֔ם לָדַ֗עַת הֲיִשְׁכֶ֤ם אֹֽהֲבִים֙ אֶת־ה' אֱלֹקֵיכֶ֔ם בְּכָל־לְבַבְכֶ֖ם וּבְכָל־נַפְשְׁכֶֽם׃ (ה) אַחֲרֵ֨י ה' אֱלֹקֵיכֶ֛ם תֵּלֵ֖כוּ וְאֹת֣וֹ תִירָ֑אוּ וְאֶת־מִצְוֺתָ֤יו תִּשְׁמֹ֙רוּ֙ וּבְקֹל֣וֹ תִשְׁמָ֔עוּ וְאֹת֥וֹ תַעֲבֹ֖דוּ וּב֥וֹ תִדְבָּקֽוּן׃ (ו) וְהַנָּבִ֣יא הַה֡וּא א֣וֹ חֹלֵם֩ הַחֲל֨וֹם הַה֜וּא יוּמָ֗ת כִּ֣י דִבֶּר־סָ֠רָה עַל־ה' אֱלֹֽקֵיכֶ֜ם הַמּוֹצִ֥יא אֶתְכֶ֣ם ׀ מֵאֶ֣רֶץ מִצְרַ֗יִם וְהַפֹּֽדְךָ֙ מִבֵּ֣ית עֲבָדִ֔ים לְהַדִּֽיחֲךָ֙ מִן־הַדֶּ֔רֶךְ אֲשֶׁ֧ר צִוְּךָ֛ ה' אֱלֹקֶ֖יךָ לָלֶ֣כֶת בָּ֑הּ וּבִֽעַרְתָּ֥ הָרָ֖ע מִקִּרְבֶּֽךָ׃
Twice in the Torah, the command of דביקות appears specifically by commandments that relate to not following the commandments of Hashem and straying toward עבודה זרה. Based on the descriptions of דביקות in the Gemara though, it's unclear what these have to do with each other.
The goal of dveikus is not just to be associated with תלמידי חכמים, who have a more intimate knowledge of Hashem, but rather it is that YOU are supposed to be an expression of the שכינה in the world. That goal can be achieved by associating with תלמידי חכמים, but not just by the technical means of doing business with them and joining their families. These are methods by which you emulate the ways they behave not just in terms of their learning and their scholarship, but in every aspect of life. That way, you also become an expression of the שכינה in every aspect of your life.
This is why the Ramban explains that the ultimate goal is that every single thought that you have is supposed to be a Hashem-related thought without any foreign idea whatsoever. This will impact your actions, and then your very existence is a pure expression of the שכינה.
עבודה זרה represents the direct opposite of this mentality. Idol worshippers recognize that the world operates due to forces beyond their control, they are just corrupted by a severe misunderstanding of who exactly operates the world. Somebody who worships idols expresses their subservience to whichever deities they may be worshipping since they have ascribed superhuman amounts of physical strength to them. They need to be worshipped because their physical capabilities demand it. But from the perspective of characteristics and qualities, these deities are no better than the base level human being who put in an iota of effort to refine himself. Therefore, עובדי ע"ז have no impetus to improve themselves, since the beings they worship are no more elevated or lofty than they are. Part of דביקות is that you shouldn't base your entire religious philosophy on dedication to something that is superior to you in only a single entity, because then you have no reason to aspire to be like that which you worship. דביקות expresses that the Being that you worship is the Perfect Being in every regard, and therefore, it is a positive endeavor to seek to emulate Hashem.
Regarding the last item in the list -- using one's money to benefit Torah scholars: this seems not to fit in with the other items in the list since לכאורה this doesn't improve the giver in any way. However, where one spends his money is an indication of his underlying values. If he trains himself to consider this an important enough cause to give money to, he will recognize the value of the people who live lives like the תלמידי חכמים, and he will also aspire to lead lives like them.
מִצְוַת עֲשֵׂה לְהִדָּבֵק בַּחֲכָמִים וְתַלְמִידֵיהֶם כְּדֵי לִלְמֹד מִמַּעֲשֵׂיהֶם כָּעִנְיָן שֶׁנֶּאֱמַר וּבוֹ תִדְבָּק. וְכִי אֶפְשָׁר לָאָדָם לְהִדָּבֵק בַּשְּׁכִינָה. אֶלָּא כָּךְ אָמְרוּ חֲכָמִים בְּפֵרוּשׁ מִצְוָה זוֹ, הִדָּבֵק בַּחֲכָמִים וְתַלְמִידֵיהֶם. לְפִיכָךְ צָרִיךְ אָדָם לְהִשְׁתַּדֵּל שֶׁיִּשָּׂא בַּת תַּלְמִיד חָכָם וְיַשִּׂיא בִּתּוֹ לְתַלְמִיד חָכָם וְלֶאֱכֹל וְלִשְׁתּוֹת עִם תַּלְמִידֵי חֲכָמִים וְלַעֲשׂוֹת פְּרַקְמַטְיָא לְתַלְמִיד חָכָם וּלְהִתְחַבֵּר לָהֶן בְּכָל מִינֵי חִבּוּר שֶׁנֶּאֱמַר וּלְדָבְקָה בּוֹ. וְכֵן צִוּוּ חֲכָמִים וְאָמְרוּ (משנה אבות א ד) "וֶהֱוֵי מִתְאַבֵּק בַּעֲפַר רַגְלֵיהֶם וְשׁוֹתֶה בַּצָּמָא אֶת דִּבְרֵיהֶם":
It is a mandatory commandment to cleave to the wise and their disciples, in order to learn of their deeds, even as it is said on the subject: "And to Him shalt thou cleave" (Deut. 10.20). Is it possible to cleave to the Shekinah? But even thus the wise men commented upon in interpreting this commandment, saying: "Cleave to the wise men and their disciples" (Ketubot, 111b). Man shall, therefore, find the necessary means to take to wife the daughter of a disciple of the wise, and to give his daughter in marriage to a disciple of the wise; to eat and drink with the disciples of the wise, to do business for and with the disciples of the wise, and to associate with them in every form of companionship, even as it is said, "And to cleave to him" (Deut. 11.22). Even so have the wise men commanded, saying: "Sit amidst the dust of their feet, and drink their words with thirst" (Pirke Abot. 1.4.).2Pesahim, 49; Baba Batra, 126a; See Shabbat, 63a. G.
להדבק בחכמי התורה - שנצטוינו להתחבר ולהתדבק עם חכמי התורה, כדי שנלמד מהם מצותיה הנכבדות, ויורונו הדעות האמתיות בה שהם מקבלים מהם, ועל זה נאמר (דברים י, כ) ובו תדבק, ונכפל הצווי במקום אחר, שנאמר ולדבקה בו. (שם יא, כב) ואמרו זכרונם לברכה (כתובות קיא, ב), וכי אפשר לו לאדם להדבק בשכינה, והא כתיב כי ה' אלקיך אש אוכלה הוא (דברים ד, כד) ? אלא הדבק לתלמידי חכמים ולתלמידיהם כאלו נדבק בו ברוך הוא, ומזה למדו רבותינו זכרונם לברכה לומר, שכל הנושא בת תלמיד חכם והמשיא בתו לתלמיד חכם ומהנהו מנכסיו כאלו נדבק בשכינה. ועוד דרשו בספרי (פיסקא דללכת בדרכיו), ולדבקה בו למוד דברי אגדה שמתוך כך אתה מכיר מי שאמר והיה העולם.
To cling to Torah sages: That we were commanded to associate [with] and cling to Torah sages, so that we learn its glorious commandments from them, and they teach us the true opinions - which are received through them - about it. And about this is it stated (Deuteronomy 10:20), "to Him shall you cling." And the command is repeated in another place, as it is stated (Deuteronomy 11:22), "and to cling to Him." And they, may their memory be blessed, said (Ketuvot 111b), "And is it possible for a person to cling to the Divine Presence - and behold it is written (Deuteronomy 4:24), 'For the Lord, your God, is a consuming fire'? Rather, one who clings to the Torah scholars and their students is as if he clings to Him, Blessed be He." And from this, our Rabbis, may their memory be blessed, learned that anyone who marries the daughter of a Torah scholar, or marries his daughter to a Torah scholar or who gives benefit from his property to a Torah scholar is as if he clings to the Divine presence. And they also expounded in Sifrei Devarim 49, "'And to cling to Him' - study the words of aggadah (the homiletical teachings, as through this, you will recognize the One who spoke and the world came into being."
The Rambam and Chinuch describe two facets of דביקות: The Rambam describes refining one's actions to become actions that express 'רצון ה in the world, while the Chinuch describes aligning one's thoughts and understandings with those of the Torah.
This also accounts for the Penei Yehoshua explaining that even those who are not תלמידי חכמים can be considered דביקים, since by associating with תלמידי חכמים, they are engrossed in refining their characters until they fully express the שכינה in the world.
וְכָל זֶה שֶׁכָּתַבְנוּ הוּא אֲפִלּוּ אִם מְסַפֵּר דִּבְרֵי גְּנוּת עַל חֲבֵרוֹ בֵּינוֹ לְבֵין עַצְמוֹ, אֲבָל אִם מְדַבֵּק אֶת עַצְמוֹ לַחֲבוּרָה שֶׁל אַנְשֵׁי רֶשַׁע וּבַעֲלֵי לָשׁוֹן הָרָע כְּדֵי לְסַפֵּר לָהֶם דִּבְרֵי גְּנוּת עַל חֲבֵרוֹ אוֹ כְּדֵי לִשְׁמֹעַ מֵהֶם, (ו) עוֹבֵר גַּם עַל הַמִצְוַת עֲשֵׂה שֶׁל (דברים י' ב'): ''וּבוֹ תִדְבָּק'', וּבָא הַפֵּרוּשׁ עַל זֶה בְּדִבְרֵי חֲזַ''ל (כְּתֻבּוֹת קי"א), לְהִתְדַּבֵּק בְּחַכְמֵי הַתּוֹרָה וּלְהַתְמִיד בִּישִׁיבָתָם בְּכָל אֹפֶן מֵהָאֳפָנִים, אֲפִלּוּ לֶאֱכֹל וְלִשְׁתּוֹת עִם תַּלְמִידֵי חֲכָמִים וְלַעֲשׂוֹת פְּרַקְמַטְיָא לְתַלְמִידֵי חֲכָמִים וּלְהִתְדַּבֵּק עִמָהֶן בְּכָל מִינֵי חִבּוּר, וְהַכָּל כְּדֵי שֶׁיִּלְמֹד מִמַעֲשֵׂיהֶן. וְלָכֵן בְּוַדַּאי, מִי שֶׁעוֹשֶׂה הֶפֶךְ זֶה, שֶׁמְדַבֵּק עַצְמוֹ עִם חֲבוּרָה שֶׁל רְשָׁעִים, עוֹבֵר עַל מִצְוַת עֲשֵׂה זוֹ
(6) And all that we have written applies even if he speaks demeaningly of his friend to him [alone]. But if he joins himself to a company of men of wickedness and speakers of lashon hara in order to speak to them demeaningly of his friend or to hear [such words] from them, he transgresses also (Devarim 10:20): "And to Him shall you cleave," which Chazal explain as cleaving to Torah scholars, frequenting their assemblies in all circumstances — even eating and drinking with Torah scholars and doing business with them and joining them in all types of activities — all this, in order to learn from their deeds. Therefore, certainly, one who does the opposite of this, joining himself to a company of wicked men, transgresses this positive commandment.
CLINGING: The matter of clinging is when a person's heart clings so much to the blessed G-d that he ceases to turn or take interest in anything else but Him. This is what Shlomo brought by way of analogy: "a lovely hind and a graceful doe, her breasts will satisfy you at all times; you shall always be infatuated with her love" (Mishlei 5:19). And in the Talmud, our sages, of blessed memory stated (Eruvin 54b): "It was said of Rebbi Eliezar ben Pedat that he sat and studied Torah in the lower market of Tzipori while his cloak lay in the upper market of the town". The ultimate goal of this trait is for a person to cling thus to His Creator at all times, and at every moment. But at the least, if he loves his Creator, certainly he will cling to Him in this manner during the times of his [divine] service.
This is not independent of the other definitions of דביקות as they are given in the Gemara. This is the 'why' that complements the Gemara's 'how.' All of the tangible actions that one takes (e.g., marrying the daughter of a תלמיד חכם, consistently interacting with תלמידי חכמים, etc.) are directed toward this goal.