But had he said, “for a deceased or living Muslim,” it would have been clearer. This is undoubtedly what he meant.
The author’s statement, “any act of devotion,” is unrestricted: he did not limit it to financial acts of devotion or physical ones.
For example, if someone voluntarily fasts a day on behalf of another person, does it benefit him? The author says: It benefits him, so long as he is a Muslim.
A second example: if a man gives charity from his wealth on behalf of someone else, does it benefit him? The answer is: Yes, it benefits him.
A third example: if a man frees a slave, intending its reward for someone else? The answer is: It benefits him.
A fourth example: if a man performs Hajj, intending its reward for someone else? The answer is: It benefits him.
If the person is deceased, then performing an act of obedience on his behalf may be appropriate, since the deceased is in need and unable to act. But if he is alive and able to perform this act himself, then this requires further consideration, because it may lead the living person to rely on the man who has drawn near to Allah on his behalf. This was not known from the Companions, may Allah be pleased with them, nor from the righteous predecessors.
What is known from them is dedicating acts of devotion to the deceased; as for the living, this is not known—except where the act is obligatory, such as Hajj. This was known in the time of the Prophet, peace and blessings be upon him, provided that the person on whose behalf Hajj is performed is incapable with an incapacity from which recovery is not expected.