There is no contradiction at all. But first, we axiomatically assume that "all Scripture is God-breathed and is useful for instruction, for conviction, for correction, and for training in righteousness, so that the man of God may be complete, fully equipped for every good work." (2 Timothy 3:16-17) This just indicates that every scripture has a God-given purpose to teach us something. If you do not accept such a proposition, this answer will not be useful to you.
Before anything else, let's get one thing clear. There are only 2 types of life; literal life, where you are living, breathing, physical being with consciousness/self-awareness, and spiritual life, where you are connected to the one true source of eternal life, God Himself. Likewise, there are only 2 types of death; literal death, where all your physical sensibilities and mental faculties have been extinguished, and spiritual death, where you are disconnected/separated, due to your sinful ways and unbelief[cf. Genesis 2:17, Ephesians 2:1, Colossians 2:13], from the one true source of eternal life, God Himself. There are absolutely no other types of death or life mentioned in the Bible... There is no such thing whatsoever as "physical/body death" or "physical/body life." When you die, your body does not die, because your body is not a living person; you are, and accordingly, you die. And when people say things like, "don't touch that dead body", what they mean is, "don't touch the body of that dead person", not that the body itself is literally dead. Also, no one refers to themselves as a living body, do they? They refer to themselves as a living person; the body is not living, you are! How can both you and your body be living beings? There aren't two living beings in you; there is only one, which is you! Whenever "death" of any kind is mentioned in the Bible, it is never talking about the death of the body, but the death of a human person.
And human persons are not body alone; they are body(physical substance) + breath of lives(spiritual substance). At the very beginning of the Bible can this fundamental truth be found(see Genesis 2:7). We are made of purely physical substance, i.e. dust, עָפָר(aphar). And we are made of purely spiritual substance, i.e. the breath of lives, נשמת חיים(Nishmat chayim). Those two work together in harmony to create a living, breathing, physical being, i.e. a living soul, which is what Adam became as per Genesis 2:7. We do not have souls; we are souls, i.e. נֶפֶשׁ(nephesh). If the physical[body] cannot function properly without spiritual[breath of lives], what leads you to surmise that the spiritual[breath of lives] can function properly without the physical[body]? The relationship between the physical and the spiritual is a harmonious relationship built on reciprocity, analogous to a positive feedback loop; the harmony is reduced to utter meaninglessness when one of its constituents performs perfectly fine without the other(the whole objective of integration between elements is to create something greater than the sum of their individual parts). It's entirely absurd to say that when unity is destroyed(at death), one constituent(body) of said unity ceases to fulfill its proper function, and the other(spirit) continues to function just fine as if the unity was never broken in the first place!
But perhaps the greatest reason to reject the proposition of the spirit being conscious after death is one of the significant implications of such a notion. If you say that the spirit is conscious after death, then you have to say that the spirit is conscious before you are even alive! How so? Genesis 2:7;
"And Jehovah God formeth the man -- dust from the ground, and breatheth into his nostrils breath of life, and the man becometh a living creature."
What does it say God did? It said he breathed the breath of lives into the nostrils of the first man; our spirit comes from God's breath, i.e. God's רוּחַ(ruach), which is His Spirit. Therefore, our spirit is not created ex nihilo; the spirit inside you comes from the Spirit of God Himself. And what do the scriptures say happens to it after death? Ecclesiastes 12:7;
"And the dust returneth to the earth as it was, And the spirit returneth to God who gave it."
It returns straight to God, i.e. it returns to the state(as part of God) it was in before it was put into your body. If you want to say that your spirit remains conscious without the body when it returns to God, you are obliged to say the same thing about it before it even left God in the first place! I mean, the scripture makes it clear that the spirit returns to the same place it was before, i.e. "to God who gave it." If you're saying that it's conscious after it leaves the body, then you have to say that it's conscious before it's put into the body, because in each instant the spirit is in exactly the same state, i.e. without body and with God. So, it is ok if you want to say that the spirit is conscious without the body after death... just so long as you are ok with saying that the spirit is conscious without the body before life! But, not only does the Bible never even slightly suggest such a notion, it also seems "anti-deity-of-Christ". I mean, God's Spirit is eternal; if our spirit comes from God's Spirit(our breath from His breath[Genesis 2:7]), and our spirit works just fine without the body, retaining all its conscious properties(i.e. mind, emotions, thoughts, self-awareness) without the body, then wouldn't that insinuate that our conscious being is also eternal? Such an attribute is reserved solely for Christ(and God), and yet we would be on the same playing field with him if our spirit is to function perfectly fine(i.e. be conscious/self-aware) without the body! I really don't like the direction this is going. But it's the inevitable conclusion to arrive at if you run the notion of the spirit retaining all consciousness/self-awareness through a reductio ad absurdum. Thus, taking all things into consideration, it is most reasonable to conclude that when a human person dies, both their body and spirit return from whence they came(i.e. the dust of the ground and God, respectively), becoming entirely non-functional(hence, no consciousness or self-awareness of any kind). This is exactly what the Bible teaches, and we will see this as of now.
Let us take a look at Ecclesiastes 9:5;
"For the living know that they will die, but the dead know nothing, and they have no more reward, for the memory of them is forgotten."
So, what is this passage trying to convey? Is Ecclesiastes 9:5 talking about spiritual life and death, as opposed to literal life and death, as I have seen some suggest(no one here in particular, but in many other places before)? Perhaps. Let us see where that takes us. But remember, we must stay consistent throughout. We don't get to pick and choose in this passage which moments are referring to spiritual life/death and which are referring to literal life/death. If we propose that the context is about spiritual life and death, then we stay wholly consistent with that proposition. No turning back.
Ecclesiastes 9:5 "For the [spiritually] living know that they will [spiritually] die, but the [spiritually] dead know nothing, and they have no more reward, for the memory of them is forgotten."
Well, you heard it here first, folks. As a spiritually alive person connected with God, through my faith in what Jesus did for me on the cross, I know(as the scripture says) that I will spiritually die someday, and lose my connection with the one true source of eternal life, God. Remember, we don't get to pick and choose which moments are about such and such; if we say that the context is about spiritual life and death, then that is what we stick to. Of course, this is ridiculous, and I'm sure you agree. My eternal hope is in Jesus, and I have a firm conviction that I will keep it to the end. I don't know that I will, but I certainly don't know that I won't. Now, let's see what happens if we insert literal death(the only other kind of death) in the passage.
Ecclesiastes 9:5 "For the [literally] living know that they will [literally] die, but the [literally] dead know nothing, and they have no more reward, for the memory of them is forgotten."
Suddenly, everything makes so much sense! If a defining attribute of life is self-awareness/consciousness, then it follows that a defining attribute of death, which is the polar opposite of life itself would be the loss of self-awareness/consciousness. It's entirely self-evident. And here this scripture is affirming that. Not only that, but this scripture is also a testament to one of humankind's unique abilities(that no animal in the world has); the ability to, not only comprehend the fact that we will die someday, but also to ponder and speculate about the fact. To be clear, animals have a concept of death; a very clear one. Just not the capability to apprehend that they themselves will inevitably die; and certainly not the capability to meditate on such a notion. Both those capabilities belong solely to humans. This scripture affirms that as well. We have no problems at all(and quite a few solutions) when we take the clear meaning of the passage. And if you subscribe to the axiom of all scripture being inspired by God, then you will believe what this scripture has to say.
Of course, we could have easily bypassed all this by going to another scripture that cannot be misunderstood in any way whatsoever(it is literally fool-proof).
Ecclesiastes 9:10 "Whatever your hand finds to do, do it with your might, for there is no work or thought or knowledge or wisdom in Sheol, to which you are going."
This is an unequivocal reference to literal death because Sheol is the place of the literally dead! It is impossible to read this in any way other than that, in Sheol, the place of the dead, the place that you and I(being mortal creatures of the dust, c.f. Genesis 3:19) will go to one day, is a place where one has no work, thought, knowledge, or wisdom of any kind! You cannot take this scripture any other way. You can, of course, always just say that it's false, which it would be if dead spirits were conscious. But you also have to say the same about these following scriptures;
Psalm 6:5 "For there is no mention of You in death; In Sheol, who will praise You?"
Psalm 88:10-12 "Will You perform wonders for the dead? Or will the departed spirits rise and praise You? Selah 11 Will Your graciousness be declared in the grave, Your faithfulness in Abaddon? 12 Will Your wonders be made known in the darkness? And Your righteousness in the land of forgetfulness?"
Psalm 115:17 "It is not the dead who praise the LORD, nor any of those descending into the silence of death."
Psam 146:4 "His spirit departs, and he returns to the earth. In that very day, his thoughts perish."
Isaiah 38:18-19 "For Sheol cannot thank You, Death cannot praise You; Those who go down to the pit cannot hope for Your faithfulness. 19 It is the living who give thanks to You, as I do today; A father tells his sons about Your faithfulness."
I go with 2 Timothy 3:16 when it says that all scripture is inspired by God. That includes all the scriptures given above(even the ones in Ecclesiastes). If a scripture unequivocally says that dead people are unconscious, then that is what I believe, because if they weren't then the scripture would be a lie, and I do not accept that the scriptures can lie when it comes to eschatological matters; I believe they are fully trustworthy in those regards. And I do not think that such precise and unambiguous statements like the ones with regards to death(Ecclesiastes 9:5; 10) can be negated by taking it within the context of the final chapter; that would be tantamount to, "I am very clearly telling you that everyone who dies becomes unconscious... Haha! Just kidding!" I do not believe that in doing so(i.e. taking it within the context of the final chapter) the truth value of such unequivocal statements is altered in any way, but only our perception of said statements. And I haven't even touched on the notion of death being likened to sleep in the New Testament, but that's a topic for another day.
So, in conclusion, the Bible makes it clear that the literal dead are wholly unconscious; unaware of anything at all whatsoever. So, is there a contradiction between Ecclesiastes 9:5 and Mark 12:26-27? No, not at all! Let's read it.
Mark 12:26-27 "But regarding the fact that the dead rise, have you not read in the book of Moses, in the passage about the burning bush, how God spoke to him, saying, 'I am the God of Abraham, the God of Isaac, and the God of Jacob'? 27 He is not the God of the dead, but of the living; you are greatly mistaken."
Remember, there are two types(and only two types) of death and two types(and only two types) of life. This can be seen clearly in Jesus' words at John 11. Let's see them.
John 11:25-26 "Jesus said to her, "I am the resurrection and the life; the one who believes in Me will live, even if he dies, 26 and everyone who lives and believes in Me will never die. Do you believe this?"
Is Jesus contradicting himself? He says that the one who believes in him will live, even though he might die. And then he says that everyone who believes in him and lives will never die. So, will everyone who believes in him never die or die someday? Which one is it? The answer is... yes! Remember, there are two types of death; literal death, where the harmony between body and spirit is broken, the nephesh(person/soul) dies, and then there is spiritual death, which is separation from God, the source of eternal life. But because of what Jesus did on the cross, we have been made alive!
Ephesians 2:1-5 "As for you, you were dead in your transgressions and sins, 2 in which you used to live when you followed the ways of this world and of the ruler of the kingdom of the air, the spirit who is now at work in those who are disobedient. 3 All of us also lived among them at one time, gratifying the cravings of our flesh and following its desires and thoughts. Like the rest, we were by nature deserving of wrath. 4 But because of his great love for us, God, who is rich in mercy, 5 made us alive with Christ even when we were dead in transgressions—it is by grace you have been saved."
Being spiritually alive means that we are now fully connected to God, the one true source of eternal life. And this connection does not break at death... this connection transcends death, because death cannot overcome the power of God! The life we have in us now is spiritual life, which is infinitely greater than literal life(and different from it. This is the most important point), because literal life will end someday, but spiritual life will never. That is why Jesus could say that the one believing in him will never die, even though they may die. Because literal death is nothing in comparison to spiritual life and holds no power over it; and we attain spiritual life by believing in Jesus, just as he himself said in John 11:25-26. And, this is precisely why we have eternal life in us right now; notice how the following passages never say that we will have eternal life, but that we have eternal life.
John 3:36 "The one who believes in the Son has eternal life; but the one who does not obey the Son will not see life, but the wrath of God remains on him."
1 John 5:11-13 "And the testimony is this, that God has given us eternal life, and this life is in His Son. 12 The one who has the Son has the life; the one who does not have the Son of God does not have the life. 13 These things I have written to you who believe in the name of the Son of God, so that you may know that you have eternal life."
Saying that the dead are totally unconscious while also alive isn't any more a contradiction as saying that you have eternal life while also being a mortal human is. It's about looking at the bigger picture, because when you do, you see that the life you gain by faith in Jesus is infinitely greater than the kind of life that you have now. It's called eternal life for a reason; if death ended it, then it wouldn't be eternal!
And for my last point. What you are spiritually has no bearing on what you are literally! You must understand this essential point.
Colossians 2:13 "And you, who were dead in your trespasses and the uncircumcision of your flesh, God made alive together with Christ, having forgiven us all our trespasses,"
The Christians Paul was talking about were literally alive, but they were spiritually dead. The fact that they were literally alive had no bearing on spiritual matters, as they were "dead in their trespasses and the uncircumcision of their flesh." When God made them alive "together with Christ," nothing changed for them literally; the change that happened was spiritual, not something that can be seen or measured, but something that transcends all that! So, if being literally alive has no bearing on spiritual matters, would it not follow that being literally dead also has no bearing on spiritual matters? If spirituality transcends all physicality, and (literal) death is itself a matter of physicality, then isn't it a corollary that literal death has no bearing on what you are spiritually? That's exactly the case! This is precisely why Jesus could call the patriarchs "living", while simultaneously acknowledging the fact that they are dead! Jesus was talking about a kind of "living" that does not have any strings attached to it by anything physical; he was expounding the fact that a spiritual connection to God(the true source of life) is not something that can be severed by literal death, but something that altogether transcends it! It's really as simple as that. There is no need to invoke the concept of "conscious spirits" or "dead bodies." None of that is needed or justified.
Thus, here is what Ecclesiastes 9:5 and Mark 12:26-27 are trying to convey, respectively;
Ecclesiastes 9:5 "For the [literally] living know that they will [literally] die, but the [literally] dead know nothing, and they have no more reward, for the memory of them is forgotten."
Mark 12:26-27 "But regarding the fact that the dead rise, have you not read in the book of Moses, in the passage about the burning bush, how God spoke to him, saying, 'I am the God of Abraham, the God of Isaac, and the God of Jacob'? 27 He is not the God of the [spiritually] dead [i.e. those disconnected from God, the only source of true life, and thus truly dead in His eyes], but of the [spiritually] living [i.e. those who are connected to God, the only source of true life, and thus truly alive in His eyes]; you are greatly mistaken."
Fundamentally, all of God's faithful servants, whether literally dead or alive, are eternally and spiritually alive in His eyes. That is all!
I hope this helps, and I hope you have an amazing day! :)