It is hard to generalize, because the authors of the pseudepigrapha might have various motivations. Moreover the are wide disagreements among scholars as to which writings should be considered forgeries or not. The Book of Enoch is an example of a text widely considered as not having been written by its supposed author but which seems to have been quoted in the New Testament (Jude 13:14). Even the authorship of some canonical books (or parts of them) is disputed, for example the Book of Daniel, parts of Isaiah, and certain letters of Paul.
Here are a few reasons why people might have written books or letters and falsely attributed them.
Channeling. The author may have believed they were acting as a channel for the spirit of the person whose name the use. The Book of Revelation, is an example of a partly channeled Revelation which Christians accept as authentic. Here, Jesus is depicted as communicating letters to the various churches through John of Patmos. An example that was not accepted, but was apparently sincere, is the Shepherd of Hermas. Both cases represent an example of a text written by someone who believed themselves to be actually channeling Jesus. Hermas' work was widely read by orthodox Christians and never condemned. The Apocalypse of Peter is another such example of a visionary report that was cited by several Church Fathers but not canonized. But there are many examples that never gained popularity in orthodox communities, for reasons of doctrinal divergence. Various Gnostic apocalypses and dialogues with Jesus fall into this category. We cannot say for certain whether these were written by authors who had false visions, or if they were written cynically for theological purposes.
Attempting to Represent the Person's Viewpoint. Some apocrypha were written to address question that a famous person never had a chance to address. A good example of this is [3 Corinthians'(https://evidenceforchristianity.org/did-paul-write-other-letters-what-about-3rd-corinthians/), which some even believed was authentic. This type could be a sub-category of "channeling," but applies to cases where the person knows he is not actually writing the words of a prophet or apostle. Those who believe Paul is not the actual author of Ephesians and the Pastoral Epistles, for example, argue that its author was a follower of Paul attempting to deal with problems that Paul did not address in his lifetime. This principle could apply to many apocryphal works.
"Fake" Acts and False Gospels. Once again there is a wide variety of such writings. Some may be the result of legends actually believed by the author, while others may be more cynical. In the case of apocryphal Acts, the fact that they are apocryphal does not mean that they are entirely fake, or even mostly false. The Acts of Paul and Thecla and the Infancy Gospel of James are examples of NT apocrypha that may contain authentic reports as well as fanciful legends that had come down to the author through oral tradition.
Cynical forgeries. In cases where the apocryphal writing is a cynical forgery, the motivation may have been monetary, as there was indeed a market for both for writings of famous people and fanciful tales of faith healers and travel to wonderous lands. Cynical forgeries could also have a theological purpose. In such cases the author knows he is lying but feels that the theological ends justify the means. The Epistle of Pilate to Tiberius is an example, where the motivation seems to be to present new evidence that the Jews and not Rome are to be blamed for the death of Christ.
It would take a complete book to analyze the whole scope of the apocyphal literature. But the above is a very brief summary as to why such things would be written: 1) Some were sincere attempts to channel the spirit of the person to whom the writing was attributed. 2. Others were attempts to represent the supposed author's views in new situations where he had not left a written record. 3) Many "fake" gospels and Acts resulted from legends that the author may have learned of through oral tradition. 4) Cynical forgeries could have had either a monetary or a theological motivation.