First, the statement that Shankara says the world is an illusion is not entirely true. The sensual universe does have a certain relative reality within time, space, and causation. If you are within the universe, if you perceive the universe, you must accept its relative reality. From an absolute standpoint, from the standpoint of Brahman, it has no absolute reality. If you stab yourself in the leg with a knife, will you see it as unreal?? No, your mind is bound within the three gunas. Where does the illusion come from? Swami Vivekananda writes (Complete Works, Vol 3, section 'Lectures and Discourses', lecture 'The Free Soul', available here - https://advaitaashrama.org/cw/content.php):
Before going into the practical part, we will take up one more intellectual question. So far the logic is tremendously rigorous. If man reasons, there is no place for him to stand until he comes to this, that there is but One Existence, that everything else is nothing. There is no other way left for rational mankind but to take this view. But how is it that what is infinite, ever perfect, ever blessed, Existence-Knowledge-Bliss Absolute, has come under these delusions? It is the same question that has been asked all the world over. In the vulgar form the question becomes, "How did sin come into this world?" This is the most vulgar and sensuous form of the question, and the other is the most philosophic form, but the answer is the same. The same question has been asked in various grades and fashions, but in its lower forms it finds no solution, because the stories of apples and serpents and women do not give the explanation. In that state, the question is childish, and so is the answer. But the question has assumed very high proportions now: "How did this illusion come?" And the answer is as fine. The answer is that we cannot expect any answer to an impossible question. The very question is impossible in terms. You have no right to ask that question. Why? What is perfection? That which is beyond time, space, and causation — that is perfect. Then you ask how the perfect became imperfect. In logical language the question may be put in this form: "How did that which is beyond causation become caused?" You contradict yourself. You first admit it is beyond causation, and then ask what causes it. This question can only be asked within the limits of causation. As far as time and space and causation extend, so far can this question be asked. But beyond that it will be nonsense to ask it, because the question is illogical. Within time, space, and causation it can never be answered, and what answer may lie beyond these limits can only be known when we have transcended them; therefore the wise will let this question rest. When a man is ill, he devotes himself to curing his disease without insisting that he must first learn how he came to have it.
There is another form of this question, a little lower, but more practical and illustrative: What produced this delusion? Can any reality produce delusion? Certainly not. We see that one delusion produces another, and so on. It is delusion always that produces delusion. It is disease that produces disease, and not health that produces disease. The wave is the same thing as the water, the effect is the cause in another form. The effect is delusion, and therefore the cause must be delusion. What produced this delusion? Another delusion. And so on without beginning. The only question that remains for you to ask is: Does not this break your monism, because you get two existences in the universe, one yourself and the other the delusion? The answer is: Delusion cannot be called an existence. Thousands of dreams come into your life, but do not form any part of your life. Dreams come and go; they have no existence. To call delusion existence will be sophistry. Therefore there is only one individual existence in the universe, ever free, and ever blessed; and that is what you are. This is the last conclusion reached by the Advaitists.
and in the next lecture 'One Existence Appearing as Many':
How does the Advaitist theory explain these various phases of heaven and hells and these various ideas we find in all religions? When a man dies, it is said that he goes to heaven or hell, goes here or there, or that when a man dies he is born again in another body either in heaven or in another world or somewhere. These are all hallucinations. Really speaking nobody is ever born or dies. There is neither heaven nor hell nor this world; all three never really existed. Tell a child a lot of ghost stories, add let him go out into the street in the evening. There is a little stump of a tree. What does the child see? A ghost, with hands stretched out, ready to grab him. Suppose a man comes from the corner of the street, wanting to meet his sweetheart; he sees that stump of the tree as the girl. A policeman coming from the street corner sees the stump as a thief. The thief sees it as a policeman. It is the same stump of a tree that was seen in various ways. The stump is the reality, and the visions of the stump are the projections of the various minds. There is one Being, this Self; It neither comes nor goes. When a man is ignorant, he wants to go to heaven or some place, and all his life he has been thinking and thinking of this; and when this earth dream vanishes, he sees this world as a heaven with Devas and angels flying about, and all such things. If a man all his life desires to meet his forefathers, he gets them all from Adam downwards, because he creates them. If a man is still more ignorant and has always been frightened by fanatics with ideas of hell, with all sorts of punishments, when he dies, he will see this very world as hell. All that is meant by dying or being born is simply changes in the plane of vision. Neither do you move, nor does that move upon which you project your vision. You are the permanent, the unchangeable. How can you come and go? It is impossible; you are omnipresent. The sky never moves, but the clouds move over the surface of the sky, and we may think that the sky itself moves, just as when you are in a railway train, you think the land is moving. It is not so, but it is the train which is moving. You are where you are; these dreams, these various clouds move. One dream follows another without connection. There is no such thing as law or connection in this world, but we are thinking that there is a great deal of connection.
As it says in the Astavakra Samhita 1.11 (Swami Nityaswarupananda translator) says:
He who considers himself free is free indeed, and he who considers himself bound remains bound. 'As one thinks, so one becomes' is a popular saying in this world, and it is quite true.