In Spanish nouns are either masculine or feminine. The article and adjectives going with this noun must match its gender.
El lápiz pequeño (everything is masculine because LÁPIZ is masculine).
La flor pequeña (everything is feminine because FLOR is feminine).
In "Buenos días", because "días" is masculine/plural the adjective must be masculine/plural "Buenos".
In "Buenas tardes" because "tardes" is feminine/plural the adjective must be feminine/plural "Buenas".
There is no rule for knowing the genre of a noun. That's why you should study the new vocabulary with the proper article: "el coche", "la moto", "la ciudad", "el pueblo"...
Hope this helps!