Well there are a few thing here. One being the definition of prayer. Is prayer communication with God as Jesus taught his disciples to pray, or is prayer using the imagination to create images of God and idyllic no realities?
To my thinking, imagining pictures while thinking is not praying. I suppose you could say, "Lord could you please give me what I picture in my mind" which may show some faith in God's ability to see your thoughts. Visualizing something could accompany prayer. It is not forbidden. God spoke to many people through visions and some of them are communicated using descriptive language in the scripturs.. It is reasonable to believe that He understands pictures also.
The second one is the first commandment the second part that said not to make any images and not to bow down to them. Especially when you apply what Jesus taught about the commandments. He said you have heard do not commit adultery, but I say if you look upon a woman and lust you have already committed adultery.
These words of Christ from Matthew 23 directed toward the scribes and Pharisees and their interpretations of the law come to mind.
4 For they bind heavy burdens and grievous to be borne, and lay them on men's shoulders; but they themselves will not move them with one of their fingers.
These religious scholars liked to add extra commands, often ignoring weightier matters of the law. The law did not forbid thinking in pictures, and there is quite a lot of descriptive detail in some of the visions, especially Ezekiel's, that would lead minds to think in pictures.
Looking at a woman lustfully was already established as wrong in the Old Testament. The ten commandments forbid lusting after one's neighbor's wife (compare 'lust' in Matthew 5 with 'covet' in the LXX of Exodus 20.) Job made a covenant with his eyes not to look upon the virgin with lust. There is no similar restriction on thinking in pictures. Some passages seem to be written so that the reader can visualize the passage.
As Christians, I believe we should be very careful about telling people that things are sinful if there is no basis in the word of God for such a claim. For example, there are those who teach that it is a sin to dance, but there are references to dancing in the Bible. You can really warp young minds with legalizing going to extremes on these things. It does make sense to tell young people about the dangers of too much physical contact with the opposite sex, not being modest, music that is antithetical to Biblical teaching, etc. Those are legitimate concerns. But 'Thou shalt not dance' is not Biblical. The Bible does not teach 'Thou shalt not visualize' either. Many people do it automatically whenever they think of a word. Heaping condemnation on such people is not helpful for them.
Applying the same principal to do not make or carve images and do not bow down to them, if you are imagining an image of God, you have just created an image of God and are praying to that image.
That sounds like a Pharisee 'hedge around the Torah' approach to me. It lead to restrictions like not drinking milk with chicken, when the OT command was not to boil a calf in its mother's milk. Chickens do not produce milk, and visualizing is not categorized as sin in scripture.
The other part is what are you trying to accomplish in prayer, to bend reality and the universe and God to your design, or to have God speak to your will changing you?
Hopefully, prayer will come from a heart transformed by the grace of God. There is plenty in scripture about praying in faith. James says that the man who doubts when he prays should not expect to receive anything of the Lord. Hebrews says to believe that He is and that He is a rewarder of them that diligently seek him. James also wrote that ye have not because ye have not. Ye ask and receive not because ye ask amiss, that ye may consume it upon your lusts.
One could visualize the outcome in their mind while praying a carnal selfish prayer or while praying something that is very much in line with the will of God according to scripture. One could do either without visualizing.