Allah's Love is Attained by Following the Messenger
This honorable Ayah judges against those who claim to love Allah, yet do not follow the way of Muhammad . Such people are not true in their claim until they follow the Shari`ah (Law) of Muhammad and his religion in all his statements, actions and conditions. It is recorded in the Sahih that the Messenger of Allah ﷺ said,
(Say (O Muhammad to mankind): "If you (really) love Allah, then follow me, Allah will love you...") meaning, what you will earn is much more than what you sought in loving Him, for Allah will love you. Al-Hasan Al-Basri and several scholars among the Salaf commented, "Some people claimed that they love Allah. So Allah tested them with this Ayah;
In previous verses, there was affirmation of Allah's Oneness and the condemnation of disbelief in it. Affirmed now is the belief in prophethood as well as the necessity of following the Messenger so that we stand informed that the rejection of prophethood or refusal to obey the Prophet ﷺ is also an act of disbelief (kufr) like the rejection of the Oneness of Allah.
Commentary
Love is something secret. Whether or not a person loves another person, or loves less or more, are questions which cannot be answered precisely. There is no measure or yard-stick to determine the truth of the matter except that one makes an educated guess based on visible conditions and dealings, for love leaves traces and signs which could help in recognizing it as such. Now, in these verses, Allah Almighty tells those who claimed that they loved Allah and hoped to be loved by Him above the real criterion of His love. In other words, if a person living in the world of today claims that he loves his Creator and Master, then, he must test it on the touch-stone of his obedience to the Messenger, that is, match it against the frequency and quality of where and how he has been following him. Once this is done, the genuine and the fake of it will be exposed right there. How much true a person turns out to be in his claim will be visible from how much he makes it a point to follow the noble prophet (علیہ السلام) ، using the guidance brought by him as the guiding force in his life. The same test will show that the weaker a person is in his claim, so equally weak he shall be in his obedience to the Prophet ﷺ .
It is a psychological reality that one who loves someone cannot at the same time love the enemy of the beloved. It is also a fact that when the beloved is a Being who has the status of one’s Creator and Sustainer, then this love will necessarily bring about in the lover the desire to obey that Being in all matters. If the love of God does not produce in him feelings of obeisance to Him, then such a love is false. A believer who is one in name only will be included among the deniers. God Himself has testified to the Prophet’s total obedience to Him in all matters. So the authentic example of a life of God-worship in this world is only such as was handed down to us by His messenger.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.