Yes, variables are allowed in predicates.
Your first expression
<xsl:value-of select="count(//*[somenode != 0])" /></p>
means "count the number of element nodes in the document that have a child element called "somenode" whose string value, converted to a number, is not equal to zero"
Your second expression
<xsl:value-of select="count(//*[$avariable != 0])" /></p>
means "if the value of $avariable is not equal to zero (which is true, because it is equal to the string "somenode") then count the number of nodes in the document, otherwise return zero"
The two expressions are both valid, but they couldn't have more different meanings.
I think you're making the mistake of thinking that variables represent textual pieces of an expression, like variables in a macro language or in some shell script languages. They don't - they represent values.
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference