All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
What you mentioned about Ibn al-Qayyim is correct. He quoted his Shaykh Ibn Taymiyyah as saying this in two of his books, which you mentioned in the question.
This Thikr is legitimate. What is problematic however is its fixation to a specific number, namely forty times. The basis of the problem is that it involves restricting a certain act of worship to a certain time and a certain number. This is a restriction of something that is unrestricted in the Sharee'ah, and it opposes what Ibn Taymiyyah and other scholars have affirmed.
Shaykh Ibn Taymiyyah said: “It is not right for anyone to institute for people any kind of Athkaar (remembrances) or invocations of prayer that have not been prescribed (by Sharee'ah), and to make them a regular act of worship which people practice regularly as they practice the five prayers regularly. In fact, this consists in innovating an act of obedience which Allaah has not allowed, in contrast to the invocations of prayer which one says occasionally without making them traditions for people. If it is not known that the latter comprises of a forbidden signification, it is not permissible to assert that it is forbidden, although it may entail being so without one realizing it. This is similar to when one invokes Allaah in prayer when necessary with an invocation with which he is inspired at that time. This and the like of it are similar.” [End of quote]
Therefore, the statement of Ibn al-Qayyim which he quoted from Ibn Taymiyyah both, should be understood according to the above clear statement. And we should seek an excuse for Ibn Taymiyyah as he may have relied on a Hadeeth which we have not come across, or may have relied upon a statement of a Companion, and there are other possibilities that do not make it permissible for us to have recourse to this Thikr on a regular basis and with this particular number and at a time that is specified for doing so, unless we come across sound evidence for this specification.
Allaah Knows best.